Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 printing large query results

Author  Topic 

caesarhernandez
Starting Member

4 Posts

Posted - 2011-10-16 : 00:43:47
Hello,

I am trying to output a very large amount of text to the results window, but it seems it has a limited number of characters (if not and I'm missing something, that would be great).

So my idea was to output the results to a file and just keep that file open in SSMS such that each time the sql is executed, the open file would just get updated each time. So I'm doing something like this to test:

declare @sql varchar(max)
set @sql = 'hello ' + CHAR(13) + 'world'

declare @cmd varchar(1000)
select @cmd = 'osql -U <user> -P <password> -S <the_server> -Q" print ''' + @sql + ''' " -o"c:\osqloutput.txt" -w500'
exec master..xp_cmdshell @cmd


...but the problem now is that the newline character is not doing anything and I can't figure out why. Any help would be greatly appreciated.

Thank you,
Caesar

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-16 : 00:56:02
try like


declare @sql varchar(max)
set @sql = 'hello ' + CHAR(10) + CHAR(13) + 'world'
.....


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

caesarhernandez
Starting Member

4 Posts

Posted - 2011-10-16 : 00:58:04
quote:
Originally posted by visakh16

try like


declare @sql varchar(max)
set @sql = 'hello ' + CHAR(10) + CHAR(13) + 'world'
.....








I got this as a result when doing that:

Msg 105, Level 15, State 1, Server CAESARLAP\SQL2K8, Line 1
Unclosed quotation mark after the character string 'hello
'.
Msg 102, Level 15, State 1, Server CAESARLAP\SQL2K8, Line 1
Incorrect syntax near 'hello
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-16 : 01:03:22
nope. thats not correct. the query is running fine for me. may be you've selected only part of statement and running

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

caesarhernandez
Starting Member

4 Posts

Posted - 2011-10-16 : 01:06:00
Really?...hmmm here is what I'm executing that is giving me the error:

declare @sql varchar(max)
set @sql = 'hello ' + CHAR(10) + CHAR(13) + 'world'


declare @cmd varchar(1000)
select @cmd = 'osql -U sa -P K67N5150 -S .\SQL2K8 -Q" print ''' + @sql + ''' " -o"c:\osqloutput.txt" -w500'
exec master..xp_cmdshell @cmd
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-16 : 01:21:53
can you try like this?
declare @sql varchar(max)

set @sql = 'hello '' + CHAR(10) + CHAR(13) + '' world'


declare @cmd varchar(1000)
select @cmd = 'osql -U sa -P K67N5150 -S .\SQL2K8 -Q" print ''' + @sql + ''' " -o"c:\osqloutput.txt" -w500'
exec master..xp_cmdshell @cmd



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

caesarhernandez
Starting Member

4 Posts

Posted - 2011-10-16 : 01:25:08
Ahh that is it...thank you!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-16 : 01:25:55
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -