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 change 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
PRINTstatements doesn’t work to view the variable contents for very long strings so you can doTo see the untruncated contents.