Pri*_*uja 6 t-sql string sql-server-2014
I have a procedure in which i have declared a variable with datatype varchar(MAX),
declare @str varchar(MAX);
set @str='select * from Table1...'
print (@str);
exec (@str);
Run Code Online (Sandbox Code Playgroud)
but when the text written inside @str goes above 8000 characters (i.e. 8193 characters) it cuts off the string and prints only 8000 characters and executing it gives error off course.
I have tried 2 solutions after some search, but it doesn't work.
1) I have tried using 2 variables of same type "varchar(MAX)", and concat it at the time of execution, but doesn't works.
2) I have tried to cast "into varchar(MAX) again" both the variables before concatinating it, and then execute it, but that also doesn't works.
CaM*_*CaM 11
SSMS cannot display a varchar greater than 8000 characters by default.
However, it can store a varchar(max) value up to 2GB.
You could set up a loop and display "chunks" of the @str data, using an 8,000 character chunk size.
此答案将向您展示如何确认@str内存中值的实际长度。
而这个MSDN文章讨论了执行。特别是:
在 SQL Server 的早期版本中,字符串限制为 8,000 个字节。这需要连接大字符串以进行动态执行。在 SQL Server 2005 中,可以指定 varchar(max) 和 nvarchar(max) 数据类型,允许字符串最多为 2 GB 的数据。
这意味着您收到的错误是其他错误,而不是对您的@str值进行截断操作的结果。
| 归档时间: |
|
| 查看次数: |
9146 次 |
| 最近记录: |