Are you using a cursor?
If so, you could always create a counter variable and increment it each time through the loop. Is this done through an application, or the query window? If it's done in a application, you may need to create a temporary table, insert the counter, plus whatever info you want, then select all the records from it after you are done with the fetch loop. If you are running it in a query window, you can just print the output.
Here's an example using the temp table
DECLARE @counter int;
@counter = 0;
CREATE TABLE #temp (counter int, otherdata varchar(255)) --Use whatever columns you need.
DECLARE tempCursor CURSOR FOR SELECT * FROM table
OPEN tempCursor
DECLARE @value AS int --or whatever your datatype is
FETCH NEXT FROM tempCursor INTO @value
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT #temp (counter, otherdata) VALUES (@counter, 'otherdata')
@counter = @counter+1
FETCH NEXT FROM tempCursor INTO @value
END
CLOSE tempCursor
DEALLOCATE tempCursor
SELECT * FROM #temp
DROP TABLE #temp
It's probably not the best solution, but it would work.
cmhampton
Junior Poster in Training
79 posts since Feb 2008
Reputation Points: 23
Solved Threads: 10