ASP.NET (35) SQL (25) JAVASCRIPT (24) HTML (14) STYLE SHEET (6) ASP (4) SCRIPT (1)

Search me out HERE!!

Declare CURSOR in SQL SERVER / Syntax for implementing CURSOR

Below is example showing simple use of CURSOR:

-- This cursor will print all Employee name from Employee table

DECLARE cur CURSOR  --Declare Cursor
FOR SELECT EmpName FROM tbl_Employee

OPEN cur
FETCH NEXT FROM cur INTO @EmpName;
 

WHILE @@FETCH_STATUS = 0
BEGIN
    PRINT 'Employee Name:' + @EmpName;

    FETCH NEXT FROM cur INTO @EmpName
END

CLOSE cur;  -- Close Cursor
DEALLOCATE cur;  -- Deallocate

No comments:

Post a Comment