Convert Oracle cursor to MSSQL cursor

How convert Oracle cursor to MSSQL.

DECLARE
CURSOR emp_cursor(p_deptno NUMBER) IS
    SELECT empno, name
    FROM emp
    WHERE deptno=p_deptno;
v_emp_cursor emp_cursor%ROWTYPE;
BEGIN
 OPEN emp_cursor(10);
            LOOP
                FETCH emp_cursor INTO v_emp_cursor;
                EXIT WHEN emp_cursor%NOTFOUND;
                DELETE FROM emp WHERE empno=v_emp_cursor.empno;
            END LOOP;
            CLOSE emp_cursor;
 commit;
END;
dzibusAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
MikeTooleCommented:
Unless I've read this wrong, you can replace this cursor logic with a simple set-based statement:

DELETE Emp WHERE deptno = 10

or, to include the use of a variable for the parameter
Declare @p_deptno int
Select @p_deptno =  10
DELETE Emp WHERE deptno = @p_deptno
0
All Courses

From novice to tech pro — start learning today.