NVARCHAR The size (8000) given to the parameter exceeds the maximum allowed (4000)

When building dynamic TSQL query string with nvarchar type in MS SQL Server, it is possible to exceed the limit  of 4000 characters, this will causes query string to be truncated and fail to run.

I have no luck with ntext type : The text, ntext, and image data types are invalid for local variables.

varchar is the correct type to use — it has a  limit of 8000 characters

you can define your query string as below:

declare @@querystring varchar(max)


declare @@querystring varchar(8000)


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s