2018年1月8日 星期一

Character Limitation in sp_executesql

I notice that when I use the sp_executesql system stored procedure in a script, my script can't exceed 4000 characters. What's the reason for this character limitation?
The sp_executesql statement's @stmt parameter is a Unicode string. Therefore, given that the maximum string length in SQL Server 2000 is 8000 bytes (without using an ntext data type) and that each character in Unicode is 2 bytes, 4000 characters is the maximum that sp_executesql can accept.

Solution:
SET @Query = 'SELECT ....' [Up To 4,000 characters, then rest of statement as below]
SET @Query = @Query + [rest of statement]

from : http://www.itprotoday.com/character-limitation-spexecutesql
from : https://stackoverflow.com/questions/4833549/nvarcharmax-still-being-truncated

沒有留言:

張貼留言