Using Cursor – Basic syntax

October 26, 2007 at 12:29 pm | In SQL Server | Leave a Comment

Using Cursor – Basic syntax

DECLARE [cursor name] CURSOR
FOR

[SELECT query ]

OPEN [cursor name]

[DECLARE variables]

FETCH NEXT FROM [cursor name] INTO [variable list]

WHILE(@@FETCH_STATUS -1)
BEGIN
IF(@@FETCH_STATUS -2)
BEGIN
[Insert/Update statements]
END
FETCH NEXT FROM [cursor name] TO[variable list]
END
CLOSE [cursor name]
DEALLOCATE [cursor name]

No Comments Yet »

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.