I am trying to use a command line program to run a stored procedure
that generates output in a comma-delimitted format. Somehow, ISQL or
OSQL always wrap the lines at 256 characters. I believe this has
something to do with the column width switch (-w). But enlarging the
column width to 800 characters max still doesn't help. The following
is a stored procedure that is essentially doing what my stored
procedure is doing:
create procedure MyTest as
set ansi_padding on
set nocount on
declare @sTest varchar(300)
-- Output three lines. Each line has 259 characters.
select @sTest = "1234 6789 ... 1234 6789"
print @sTest
select @sTest = "1 3 5 7 9 ... 1 3 5 7 9"
print @sTest
select @sTest = "1 3 5 7 9 ... 1 3 5 7 9"
print @sTest
set nocount off
return( 0 )
I invoke this stored procedure using this command:
isql -SMyDbSrv -E -dMyDb -w800 -x800 -h-1 -n -Q"exec MyTest"
-oMyTest.txt
-- or --
osql -SMyDbSrv -E -dMyDb -w800 -h-1 -n -Q"exec MyTest" -oMyTest.txt
But they have the same problem. The output lines all wrap around at
256 characters.
Strangely, if I store the result in a temporary table, and then use
SELECT to output the result from the temporary table, I will not have
that problem. Seem like the "-w" switch only works for output from
tables, but not for output coming from PRINT. Unfortunately, using
this approach has another set of problems (one blank space in front of
each line, "number-of-rows affected" shows up at the bottom).
Therefore, I would like to stick with using PRINT statements to output
the result.
Please suggest a way to fix this line-wrapping-around problem.
Thanks.
Jay Chan