views:

267

answers:

2

I'm using T-SQL and I want to print out a result set. This is just a ~2x6 (dynamic size) set but I'm not entirely sure how I can do this without using a CURSOR. Is there a nice way I can print these to console/email/wherever?

+1  A: 

If you want to print them from a bat file you can use osql.exe to execute the query - the results will be displayed to the screen. You may want to use trunc and/or set colwidth settings so that it's legible.

Arnshea
+1  A: 

You mean you have two columns and six rows and you want to output them somehow without a cursor?

you can concatenate different rows without a cursor, e.g. assuming you have two string columns called col1 and col2:


declare @combined varchar(2000)
set @combined = ''

select @combined = @combined + char(13) + isnull(col1,'*') + ' ' + isnull(col2,'*')
from yourtable

print @combined

codeulike