I'm following the book 'Sams Teach Yourself SQL in 10 Minutes' in Lesson 21 about cursors. I've created the cursor in the book with the code below.
Then I tried to open the cursor as stated in the book using the Open method as below and it gives me an error:
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'cursor'.
So I look on the internet and try just open and the name of the cursor and I get the error:
Msg 16916, Level 16, State 1, Line 1
A cursor with the name 'CustCursor' does not exist.
I declare the cursor again with the same name and I get the error:
Msg 16915, Level 16, State 1, Line 3
A cursor with the name 'CustCursor' already exists.
So what I've figured is that the cursor 'CustCursor' is already created but I can't open it. Can anyone tell me what's going on?
declare CustCursor cursor
select * from customers
where cust_email is null;
open cursor CustCursor;