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
 Old Forums
 CLOSED - General SQL Server
 print variable contents

Author  Topic 

-Dman100-
Posting Yak Master

210 Posts

Posted - 2006-07-04 : 18:18:42
I have the following table which I want to display the output using print.

Here is my table:

dbo.press_releases
headline varchar(255)
description varchar(294)
content text
pr_date datetime
pdf varchar(255)
id int primary key


Using query analyzer I was trying the following statement to display the contents:

DECLARE @pr varchar(8000)

SET @pr = (SELECT headline, description, content
FROM dbo.press_releases
WHERE id = 11)

print @pr

Thanks for any help.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-07-04 : 18:25:25
You have to declare one variable for each column

select @hl = headline, @dc = description, @ct = convert(varchar(8000), content)
from dbo.press_releases
where id = 11




KH

Go to Top of Page

-Dman100-
Posting Yak Master

210 Posts

Posted - 2006-07-04 : 18:37:26
Thank you.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-07-05 : 04:15:30
or

If all columns are of varchar type, then

DECLARE @pr varchar(8000)

SET @pr = (SELECT headline+','+ description+','+ content
FROM dbo.press_releases
WHERE id = 11)

print @pr


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -