sp_executesql 可能用 exec sp_executesql @sqltext,@paramstring,@urlM_ID output 来得到动态执行中返回值,@sqltext的长度可能超过了4000字符,可以使用nvarchar(max)解决,类似于:
declare @request1 nvarchar(4000)
declare @request2 nvarchar(4000)
declare @request3 nvarchar(max)
– Fill @request1 with 4000 chars max
– Fill @request2 with 4000 chars max
SET @request3 = CAST (@request1 AS nvarchar(MAX)) + CAST (@request2 AS nvarchar(MAX))
EXEC sp_executesql @request3