有了这个陈述,我可以执行得很好:
SELECT sum(Amount) As '350' FROM Withdrawal
WHERE WholeSellerId = 'Someone' AND DateAdded = '02-04-2016' And ProductId = '1'
但是当我把它放在像这样的存储过程中时:
ALTER PROCEDURE [dbo].[GetWithJR]
@WholeSellerId varchar(50),
@ProductId varchar(30),
@StartDate date
AS
BEGIN
SELECT sum(Amount) As '350' FROM Withdrawal
WHERE WholeSellerId = @WholeSellerId AND DateAdded = Cast(@StartDate as date) And ProductId = @ProductId
END
并按原样执行:
exec [dbo].[GetWithJR] 'Someone', '02-04-2016', '1'
我收到此错误:
Msg 8114, Level 16, State 5, Procedure GetWithJR, Line 0
Error converting data type varchar to date.
我尝试使用Convert(date, @StartDate, 110)
和
Cast(@StartDate as date)
你能告诉我有什么问题吗?感谢。