June 17, 2014 at 11:19 pm
Hello every Body
Is below code is correct or incorrect:
DECLARE @DocNo nvarchar(20)
DECLARE @inMode bit
IF @inMode = 0 --All Document
DECLARE Doc_Cursor CURSOR FOR SELECT DocNo from Document
ELSE
DECLARE Doc_Cursor CURSOR FOR SELECT DocNo from Document WHERE DocNo BETWEEN @inDocNo1 AND @inDocNo2
OPENDoc_Cursor
FETCH NEXT FROM Doc_Cursor INTO @DocNo
WHILE @@FETCH_STATUS = 0
BEGIN
---Some expressions
FETCH NEXT FROM Doc_Cursor INTO @DocNo
END
June 17, 2014 at 11:31 pm
You have to declare missing variables
---------------------------------------------------
"Thare are only 10 types of people in the world:
Those who understand binary, and those who don't."
June 18, 2014 at 12:02 am
I Set the code in side SP And When I Run my code I see this error:
Msg 16958, Level 16, State 3, Line 257
Could not complete cursor operation because the set options have changed since the cursor was declared.
June 18, 2014 at 12:14 am
If you script the stored proc as CREATE from SSMS, you will see something like this at the start:
set ansi_nulls on
go
set quoted_identifier on
go
If you make sure that your set options are the same as those saved with the proc definition, you should avoid the error.
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
June 18, 2014 at 7:45 am
Even better would be to get rid of that cursor entirely. From what you posted I don't see a need for a cursor. If you want help to make this process faster than you ever dreamed possible post some ddl and sample data in accordance with the first link in my signature. We can most likely make that cursor go the way of the dodo bird.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
June 18, 2014 at 8:08 am
Sean Lange (6/18/2014)
Even better would be to get rid of that cursor entirely. From what you posted I don't see a need for a cursor. If you want help to make this process faster than you ever dreamed possible post some ddl and sample data in accordance with the first link in my signature. We can most likely make that cursor go the way of the dodo bird.
It's a real shame that I can't mark this as the correct answer.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply