Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
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 @variableand return the following results set:EmployeeID LastName ----------- -------------------- 5 Buchanan8 Callahan1 Davolio9 Dodsworth2 Fuller7 King3 Leverling4 Peacock6 SuyamaObviously 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