如何使用打印语句打印 VARCHAR(MAX)? [英] How to print VARCHAR(MAX) using Print Statement?
本文介绍了如何使用打印语句打印 VARCHAR(MAX)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个代码:
DECLARE @Script VARCHAR(MAX)
SELECT @Script = definition FROM manged.sys.all_sql_modules sq
where sq.object_id = (SELECT object_id from managed.sys.objects
Where type = 'P' and Name = 'usp_gen_data')
Declare @Pos int
SELECT @pos=CHARINDEX(CHAR(13)+CHAR(10),@script,7500)
PRINT SUBSTRING(@Script,1,@Pos)
PRINT SUBSTRING(@script,@pos,8000)
脚本的长度约为 10,000 个字符,并且由于我使用的打印语句最多只能容纳 8000 个字符.所以我使用了两个打印语句.
The length of the Script is around 10,000 Characters and Since I am using print Statement which can hold only max of 8000. So I am using two print statements.
问题是当我有一个 18000 个字符的脚本时,我曾经使用 3 个打印语句.
The problem is when I have a script which is of say 18000 characters then I used to use 3 print statements.
那么有没有办法根据脚本的长度设置打印语句的数量?
So Is there a way that I could set the number of print statements depending on the length of the script?
推荐答案
您可以根据脚本长度除以 8000 的计数执行 WHILE
循环.
You could do a WHILE
loop based on the count on your script length divided by 8000.
EG:
DECLARE @Counter INT
SET @Counter = 0
DECLARE @TotalPrints INT
SET @TotalPrints = (LEN(@script) / 8000) + 1
WHILE @Counter < @TotalPrints
BEGIN
-- Do your printing...
SET @Counter = @Counter + 1
END
这篇关于如何使用打印语句打印 VARCHAR(MAX)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文