在“' - '附近出现错误"语法不正确"执行存储过程时

时间:2015-05-06 11:43:03

标签: sql-server stored-procedures syntax-error

我使用两个输入参数和两个输出参数成功创建了一个存储过程。当我执行此程序时,我收到错误

  

' - '

附近的语法不正确

靠近第一个参数。

\0

这是执行结果:

ALTER PROCEDURE [dbo].[Agent_interactions_report]
(
@StartDate date, 
@EndDate date,
@ERRORCODE AS INT OUTPUT,
@ERRORDESCRIPTION AS VARCHAR(4000) OUTPUT
)
AS
BEGIN
    SET NOCOUNT ON;

    begin Try

    select 
        cast([CallStartTime] as Date) as Date, 
        [AgentID] as [Agent ID], [Agent_Name] as [Agent name], 
        [CustomerID] as [Cust-ID], [Account_Number] as [Account number],
        [Transaction_Des] as [Transaction], 
        CallStartTime AS [Call start time], 
        CallEndTime AS [Call end time], CallID as [Call ID]
    from  
        [TBL_AGENT_TRANSACTIONS]
    where 
        cast(CallStartTime as DATE) >= @StartDate 
        and cast(CallEndTime as Date) <= @EndDate
end Try
begin catch
        SET @ERRORCODE = ERROR_NUMBER() 
        SET @ERRORDESCRIPTION = ERROR_MESSAGE() 
end catch

END

我在&#34; @StartDate = 2015-04-27附近收到错误,&#34;但是当我通过输入输入参数手动执行SP时,我得到了预期的结果。

注意:

由于我的声誉低于10,我不应该上传截图,这对了解问题会更有用。如果您需要更多信息,请与我们联系。

2 个答案:

答案 0 :(得分:7)

以这种方式处理日期时,您需要将它们封装在引号中!它无法识别您拥有的数据类型,并认为您正在发送字符串。

答案 1 :(得分:2)

在日期周围尝试引号?

@StartDate = '2015-04-27',
        @EndDate = '2015-04-27',