C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






Implementation of Cursor in SQL Server


Posted Date: 24 Sep 2008    Resource Type: Code Snippets    Category: SQL

Posted By: Bunty       Member Level: Diamond
Rating:     Points: 10



Hi,
This code scippets shows how to implement cusor in sql server.


/* Create two variables that would store the values returned by the fetch statement */

DECLARE @DepartmentName char(25)
DECLARE @DepartmentHead char(25)

/* Define the cursor that can be used to access the records of the table,row by row */

DECLARE curDepartment cursor for
SELECT vDepartmentName,vDepartmentHead from Department

-- Open the cursor

OPEN curDepartment

-- Fetch the rows into variables

FETCH curDepartment into @DepartmentName,@DepartmentHead

--Start a loop to display all the rows of the cursor

WHILE(@@fetch_status=0)
BEGIN
Print 'Department Name =' + @DepartmentName
Print 'Department Head =' + @DepartmentHead

--Fetch the next row from the cursor
FETCH curDepartment into @DepartmentName,@DepartmentHead
END

-- Close the cursor

CLOSE curDepartment

-- Deallocate the cursor

DEALLOCATE curDepartment

Thanks and Regards
S.S.Bajoria




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sql server  .  Cursor  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: MYSQL Procedure with SQLTransactions and Exception Handling
Previous Resource: Pagination in SQL Server 2005
Return to Discussion Resource Index
Post New Resource
Category: SQL


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

UK Conference calling Company

Contact Us    Privacy Policy    Terms Of Use