printing sql select result in management studio

Easter Bunny

Expert Member
Joined
Feb 14, 2007
Messages
2,081
Reaction score
1,154
Location
-53.040671,72.596062
how will i go about printing a single column result set in management studio? i've updated a table by inserting values from a select query, but now i need to print each value i inserted.

i'm not at my desk now, but what i did was insert records into a table that were in the temporary table i created and not in the actual table. the records i insert are caught with the "output" clause and inserted into a different temporary table with one column.

now i just need to print something like:

Access Denied error inserted
Wrong Code error inserted
.... etc

any ideas? :)
 
Something like this?

DECLARE @txt NVARCHAR(MAX);

SELECT @txt = (
SELECT AccountNumber FROM tblAccountDetails
WHERE UniqueID = '992'


);

PRINT @txt;
 
Last edited:
Do you want to output to the screen like Beerisgood shows ? or do you actually want to print it out with a printer ?
 
i tried something similar, but got no printing happening, even though it shows it inserted rows.

the example i found and trued was along the lines of

declare @txt nvarchar(8000)
select @txt = @txt + description
from table

print @txt


i'm on my way back to my pc so i'll give yours a shot and see what happens. thanks. ;)
 
i tried something similar, but got no printing happening, even though it shows it inserted rows.

the example i found and trued was along the lines of

declare @txt nvarchar(8000)
select @txt = @txt + description
from table

print @txt


i'm on my way back to my pc so i'll give yours a shot and see what happens. thanks. ;)



Looks wrong to me... Try beers method... or insert into
 
got it! beerisgood's suggestion got me to tweak my google search. found a suggestion that selects the data as xml, but in a csv format, so i used replace to convert the commas to newlines. :)

now i'm happy. :)

Code:
declare @updateText nvarchar(max)

select @updateText = replace(
( 
  select ',' + convert(nvarchar(80), ErrorDesc)
  from @ErrorsInserted
  for xml path(''))
  ,','
  ,CHAR(13)+CHAR(10))

print @updateText
 
Nice one gz :)


Edit: I removed the word Test

SELECT AccountNumber FROM tblAccountDetails Test

Shouldn't be there.
 
Last edited:
Top
Sign up to the MyBroadband newsletter
X