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 2000 Forums
 SQL Server Development (2000)
 send the results of a query to a variable

Author  Topic 

lfmn
Posting Yak Master

141 Posts

Posted - 2001-07-02 : 14:40:41
I'd like to capture the results of a query in a variable. As an example:

declare @variable varchar(500)

set @variable = (select EmployeeID, LastName from Employees)

select @variable

and return the following results set:

EmployeeID LastName
----------- --------------------
5 Buchanan
8 Callahan
1 Davolio
9 Dodsworth
2 Fuller
7 King
3 Leverling
4 Peacock
6 Suyama

Obviously this doesn't work and I've found a quick workaround which involves ....... A CURSOR ..... don't anybody get upset

If anyone knows a better way to do this, I'd appreciate your comments.

cursors are like hammers - sometimes you have to use them
   

- Advertisement -