gpt4 book ai didi

sql-server - 执行存储过程时出现错误 "Incorrect syntax near ' -' "

转载 作者:行者123 更新时间:2023-12-03 13:12:23 24 4
gpt4 key购买 nike

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

Incorrect syntax near '-'

靠近第一个参数。

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

这是执行结果:

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'

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

注意:

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

最佳答案

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

关于sql-server - 执行存储过程时出现错误 "Incorrect syntax near ' -' ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30075714/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com