Not logged in - Login
< back

Output long strings

Use the following SQL to output long strings in SQL Management Studio.




-- declare a variable to hold our big string
declare @bigString varchar(max)

-- Add code to store the big string into our @bigString variable
select @bigString = sResponse
from S1_LogAQ a
where a.lRowID = 5288

-- get the total length of the big string
declare @totalLen int
set @totalLen = len(@bigString)

declare @size@sizePerLine int
       , @start int
       , @sub varchar(max)

-- set the start position
set @start = 1
-- set the number of characters to print on each line
set @size@sizePerLine = 5000

-- keep going while the start position is within the size of the big string
while (@start <= @totalLen)
begin
       -- get the substring to print
       set @sub = substring(@bigString, @start, @size)@sizePerLine)
       -- print it
       print @sub

       -- set the start position for the next time around
       set @start += len(@sub)
end