Translate

Tuesday, November 6, 2012

SQL Server cursor example




DECLARE @first_name INT
DECLARE @age        INT

DECLARE test_cursor CURSOR
FOR
        SELECT          first_name,age
        FROM            myTable
        WHERE           last_name='Biden'
       
       
OPEN test_cursor

FETCH NEXT
FROM  test_cursor
INTO  @first_name,@age


WHILE @@FETCH_STATUS = 0
BEGIN
        Select  @first_name,@age
       
            FETCH NEXT
            FROM  test_cursor
            INTO  @first_name,@age
END


CLOSE test_cursor
DEALLOCATE test_cursor




No comments:

Post a Comment

Comments will appear once they have been approved by the moderator