EXECUTE @Var character limit SQL Server 2008 R2

寵の児 提交于 2019-12-24 05:54:51

问题


I've been looking all over for an answer to this, but nothing is explicit so hopefully someone knows off the top of their head.

When using EXECUTE with a VARCHAR(MAX) variable, is there a character limit? I've done some experimenting and it seems that when load a variable and then call EXECUTE @var, there is a character limit on what is actually passed through to the server. When calling EXECUTE without the variable and just building the string there, everything appears to work.... is there a reason for this? The error message returned is:

The Name ' (insert around 643 out of 881 characters of my SQL statement variable here) ' is not a valid identifier

Does anybody know anything about why this might be happening? EXECUTE @var fails, EXECUTE 'string' works...


回答1:


I thought is was: exec @mystr --assumes the string is a procedure name and is limited to 8000 bytes

exec (@mystr) --has the 2 gigabyte limit.




回答2:


In SQL Server 2008, the limit seems to be strings up to 2 GB, according to msdn:

Using EXECUTE with a Character String

In earlier versions of SQL Server, character strings are limited to 8,000 bytes. This requires concatenating large strings for dynamic execution. In SQL Server, the varchar(max) and nvarchar(max) data types can be specified that allow for character strings to be up to 2 gigabytes of data.

Here is the link with all the information.

If you are having problems, it may be the way you are concatenating the strings on your variable.



来源:https://stackoverflow.com/questions/13567448/execute-var-character-limit-sql-server-2008-r2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!