不正确的语法附近“sp_executesql的”
-
18-09-2019 - |
题
我不明白为什么给我的错误以下。我认为这是关系到注释部分,但@SQL数据类型为nvarchar(4000)。
BEGIN
sp_executesql N'SELECT ''td'''
--sp_executesql @SQL, N'@StartDate DateTime, @EndDate DateTime, @End2 DateTime, @Program varchar(4)', @StartDate, @EndDate, @End2, @Program
END
解决方案
这是为什么:
-- This works just fine: BEGIN -- You must have an exec before your sp_executesql or it will not work in a block exec sp_executesql N'SELECT ''td''' END
您不能只是调用存储过程没有 EXEC 当你在一个块。
其他提示
为什么你有这样的封闭在一个BEGIN ... END?运行sp_executesql的外部的块将工作。
可选地可以sp_executesql的前加上一个的 EXEC 强>
在某些情况下,我不得不使用主,以及:
exec master..sp_executesql
不隶属于 StackOverflow