SQL Server Cursor data as result of stored procedure

Posted by Dmitry Borovsky on Stack Overflow See other posts from Stack Overflow or by Dmitry Borovsky
Published on 2010-04-04T13:02:45Z Indexed on 2010/04/04 13:33 UTC
Read the original article Hit count: 256

Hello,

I have a stored procedure

DECLARE cursor FOR SELECT [FooData] From [FooTable];
OPEN cursor ;  
FETCH NEXT FROM cursor INTO @CurrFooData;
WHILE @@FETCH_STATUS = 0
BEGIN
  SELECT @CurrFooData AS FooData;
  INSERT INTO Bar (BarData) VALUES(@CurrFooData);
  FETCH NEXT FROM cursor INTO @CurrFooData;
END;
CLOSE cursor 
DEALLOCATE cursor 

But in result I have a lot of tables, not one. How can I return one table with 'FooData' column and all '@CurrFooData' rows?

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about stored-procedures