February 8, 2013 at 5:21 am
Hi Team,
i have a stored procedure in that am using a cursor with name "C_MTS" (not mentioned local|global)
DECLARE C_MTS CURSOR
STATIC FOR SELECT EmpID,EmpName,Salary from Ctest
OPEN cursor
FETCH
CLOSE
DEALLOCATE
--
and am using same cursor"C_MTS" in another stored procedure.
is it possible to declare same cursor in two stored proc's,
Please suggest...
February 8, 2013 at 5:40 am
Yes its true practically as you are de allocating
cursor in the end of first cursor.
So the cursor can be used once again.
February 8, 2013 at 7:58 am
That's fine. You can name variables the same thing between procedures and other stuff. It's not like creating a permanent table or a global temporary table. The scope of these things is within the execution context they're in.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
February 8, 2013 at 8:02 am
It would be FAR better to remove the cursor from both of your procs. 😀
_______________________________________________________________
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/
February 8, 2013 at 8:08 am
Sean Lange (2/8/2013)
It would be FAR better to remove the cursor from both of your procs. 😀
Ha! Probably a true statement.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
February 8, 2013 at 9:47 am
i believe that if your within cursor in one SP (lets say its named aCURSOR)
and you make a call to another SP that also has a cursor with the same name, you will have problems.
other than that, it should be OK.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply