动态SQL字符长度超过4000,SQL SERVER 2005 SP_EXECUTESQL打破了这个限制。
declare @cSQLKey nvarchar(max) --查询语句
declare @cWhereKey nvarchar(max) --条件语句
。。。。。。文章来源:https://www.uudwc.com/A/BvPW4/
set @cWhereKey = N'where 1=1 '
if not ISNULL(@org ,'')=''
BEGIN
set @cWhereKey = @cWhereKey+ N' and PM_PurchaseOrder.org like '''+@org+ ''' '
END
。。。。。。。。文章来源地址https://www.uudwc.com/A/BvPW4/
set @cSQLKey = @cSQLKey + @cWhereKey
print @cSQLKey
--exec @cSQLKey
execute sp_executesql @cSQLKey Output -- 输入查询结果