How can I return a sql select into a sql variable

Posted by Matt on Stack Overflow See other posts from Stack Overflow or by Matt
Published on 2010-05-02T23:24:15Z Indexed on 2010/05/02 23:27 UTC
Read the original article Hit count: 321

Filed under:
|
|
|
|

Hi,

I'm trying to put the results of a SELECT into a variable and loop through the results to manipulate that data, all in the same stored proceedure... Here's what I have so far:

DECLARE @i int

@Result = (SELECT * FROM UserImport)

SET @i = 0
WHILE @i < (SELECT Count(@Result) As Count)
BEGIN
   /* Do Stuff */
END

I know I'm way off because it's saying @Result was not declared, but I'm not sure how to declare a variable to be able to hold the results of a SELECT statement.

Can anyone tell me where i'm going wrong and how to fix it?

Thanks,
Matt

© Stack Overflow or respective owner

Related posts about sql

Related posts about select