Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
靠近'的语法不正确;sp#u executesql';_Sql_Sql Server 2005_Tsql_Dynamic Sql - Fatal编程技术网

靠近'的语法不正确;sp#u executesql';

靠近'的语法不正确;sp#u executesql';,sql,sql-server-2005,tsql,dynamic-sql,Sql,Sql Server 2005,Tsql,Dynamic Sql,我不明白为什么下面给了我这个错误。我认为它与注释掉的部分有关,但是@SQL是nvarchar(4000) 你为什么要把这封信封在一封信里。。。结束?运行sp_executesql外部块将起作用 (可选)您可以在sp_executesql之前放置一个exec。这就是为什么: -- This works just fine: BEGIN -- You must have an exec before your sp_executesql or it will not work in a bloc

我不明白为什么下面给了我这个错误。我认为它与注释掉的部分有关,但是@SQL是nvarchar(4000)


你为什么要把这封信封在一封信里。。。结束?运行sp_executesql外部块将起作用

(可选)您可以在sp_executesql之前放置一个exec

这就是为什么:

-- 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 --这很好: 开始 --在sp_executesql之前必须有一个exec,否则它将无法在块中工作 exec sp_executesql不选择“td” 结束
当您处于块中时,不能在没有执行的情况下调用存储的proc

在某些情况下,我也不得不使用master:

exec master..sp_executesql 

您可以在不使用and exec的情况下调用存储过程,但仅当对存储过程的调用是块中的唯一语句时。它必须是第一条语句,而不一定是唯一的语句。
exec master..sp_executesql