I think it's pretty clear what I'm up to. Essentially I want the cursor to act
like an recordset. This example is the essence of it - I will be doing a little
more to the string so, take my word for it, it isn't just the a case of throwing
away the Cursor and building a string. Also note that I am not selecting from a
table, rather, I will be building strings that need to be stored. In VB this
would be an array where each item is later concatenated with another string.
DECLARE @Row varchar(10)
DECLARE @Output varchar(50)
DECLARE @i smallint
---I'll be looping here adding values
select @i = 0
while @i <>6
begin
DECLARE Cursor1 CURSOR FOR
SELECT 'Row' + @i
select @i = @i +1
end
---Then I'll be building a string from the stored values
OPEN Cursor1
FETCH NEXT FROM Cursor1
INTO @Row
WHILE @@FETCH_STATUS < 0
BEGIN
FETCH NEXT FROM Cursor1
INTO @Row
select @Output = @Output + @row /*Obviously there will be
additional stuff here*/
END
-- Finally I do 'stuff' with the concatenated string
print @Output
CLOSE Cursor1
DEALLOCATE Cursor1