Saturday, June 4, 2011

Working with CURSOR

it's old fasion but important in some cases

DECLARE @AuthorID char(11)

DECLARE c1 CURSOR READ_ONLY
FOR
SELECT au_id
FROM authors

OPEN c1
FETCH NEXT FROM c1 INTO @AuthorID

WHILE @@FETCH_STATUS = 0
BEGIN
 PRINT @AuthorID
 FETCH NEXT FROM c1
 INTO @AuthorID
END

CLOSE c1
DEALLOCATE c1

No comments:

Follow by Email