执行存储过程时出现错误“语法不正确' - '”

时间:2022-08-25 19:12:44

I have successfully created a stored procedure using two input parameters and two output parameters. when I executed this procedure, I'm getting an error

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

Incorrect syntax near '-'

' - '附近的语法不正确

near the first parameter.

靠近第一个参数。

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

This is the executed result:

这是执行结果:

DECLARE @return_value int,
        @ERRORCODE int,
        @ERRORDESCRIPTION varchar(4000)

EXEC    @return_value = [dbo].[Agent_interactions_report]
        @StartDate = 2015-04-27,
        @EndDate = 2015-04-27,
        @ERRORCODE = @ERRORCODE OUTPUT,
        @ERRORDESCRIPTION = @ERRORDESCRIPTION OUTPUT

SELECT  @ERRORCODE as N'@ERRORCODE',
        @ERRORDESCRIPTION as N'@ERRORDESCRIPTION'

I'm getting error near "@StartDate = 2015-04-27," but when I executed the SP manually by giving this inputs to the input parameters i'm getting the expected result.

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

Note:

Since my reputation is below 10 i'm not supposed to upload screenshot which will be more useful to understand the issue. Please let me know if you need more info.

由于我的声誉低于10,我不应该上传截图,这对于理解这个问题会更有用。如果您需要更多信息,请告诉我。

2 个解决方案

#1


When handling dates in this way you will need to encapsulate them in quotation marks! It's failing to identify the type of data that you have and believes that you are sending a string.

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

#2


Try quotation marks around the dates?

试试日期周围的引号?

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

#1


When handling dates in this way you will need to encapsulate them in quotation marks! It's failing to identify the type of data that you have and believes that you are sending a string.

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

#2


Try quotation marks around the dates?

试试日期周围的引号?

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