开发者

sp_executeSQL and Statment with more than 2000 characters

I'm using dynamic SQL and I need to exec a long SQL query, First I declare @var with query as nvarchar(4000), but my query is longer than 4000 chars. I try to chang开发者_运维百科e to nvarchar(8000) but raise an Exception that can't be longer than 4000 chars.

Finally I declare var as varchar(8000) and no error ocurrs , but when I going to exe sp_executeSQL raise and error that sp_executeSQL expect a ntext/nchar/nvarchar.

How I can exec a longer Sql Query with sp_executeSQL ? Thnks!

I'm using Sql Server Express 2005.


As you are on 2005 you can use declare @var nvarchar(max) for up to 1 billion characters.

You will find using PRINT statements doesn't work to view the variable contents for very long strings so you can do

SELECT @var AS [processing-instruction(x)] FOR XML PATH('')

To see the untruncated contents.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜