Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
SQLIsTheDevil
Posting Yak Master
177 Posts |
Posted - 2010-03-16 : 14:49:33
|
Hello,Very quick: Can I declare a cursor on a stored procedure?I am using someone else's stored procedure which, when executed, displays a table of results. The only way I think I can manipulate the table, without modifying the stored procedure, is to use cursors. I tried declaring a cursor for the stored procedure, where one would normally put a select statement, but it's not working. Again, the procedure I wish to obtain results from cannot be modified. I have to code around it. Any suggestions would be most welcome. Thank you. |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-03-17 : 01:43:58
|
why do you need a cursor? Is it not possible to achieve your result using set based solution after you get procedure result onto a temp table as Tara suggested------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
venkat09
Starting Member
17 Posts |
Posted - 2010-03-31 : 07:35:47
|
The answer is NO.You can do this. create table #TempTbl (col1 datatype1, col2 datatype2, ....)insert into #TempTbl (col1 datatype1, col2 datatype2, ....) exec someOneElse'storedProcedure/*Of course the temp table should have the same columns in the same order as that of the result-set of "someOneElse'sStoredProcedure"*/declare cur Cursor on select col1, col2, ... from #TempTbl....Your code........Ofcourse using a cursor is the least efficient way. You could manipulate the results in, an update statement with using what ever condition you want to use on any number of subsets of the result-set/tablular results.Venkat R. Prasad |
|
|
DBA in the making
Aged Yak Warrior
638 Posts |
Posted - 2010-03-31 : 07:55:35
|
Don't use a cursor unless you absolutely have to. They're as slow as buggery.There are 10 types of people in the world, those that understand binary, and those that don't. |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2010-03-31 : 07:57:00
|
Wish we had method overriding and interfaces in SQL Server But then again, beauty of SQL will be lost!Harsh Athalyehttp://www.letsgeek.net/ |
|
|
|
|
|
|
|