October 29, 2013 at 7:40 am
I have a table to scan and on each record to execute stored procedure. This procedure returns a value which I need to use to update table's column.
The process seems to be straight forward - create a cursor, fetch next, run stored procedure, update the column, fetch next, run stored...
Is there any better approach you would advise to look into, please?
Thanks for the ideas.
October 29, 2013 at 7:43 am
If the stored procedure is converted to a function, you could use CROSS APPLY to call the function for each row.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
October 29, 2013 at 7:59 am
That's interesting indeed, thank you!
Do you mean I can use it as a part of my update:
UPDATE myTable
SET myTable.Column1 = cApply.Column1
FROM myTable
CROSS APPLY (SELECT Column1 FROM myFunction WHERE ....) cApply
ON myTable.id = cApply.id
Thank you again!
October 29, 2013 at 8:14 am
I haven't done it myself, but I believe it will be possible.
Some examples on APPLY:
SQL Server CROSS APPLY and OUTER APPLY[/url]
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
October 29, 2013 at 8:35 am
Thank you!
October 29, 2013 at 9:39 am
If you give the Stored Procedure code and the cursor code, we might be able to give a better solution. You should give DDL and sample data as well to work on it. 🙂
October 29, 2013 at 9:51 am
Thank you Luis,
I am looking for the ideas at the moment. Want to play with various suggestions people may come up here, like CROSS APPLY for example.
October 29, 2013 at 10:19 am
If you're looking for ideas, this phrase by Jeff Moden might help you.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
October 29, 2013 at 10:35 am
Luis Cazares (10/29/2013)
If you're looking for ideas, this phrase by Jeff Moden might help you.First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
To expand on what Luis said, I'd like to add a warning: Once you move to set-based code and tally tables, you'll never want to go back. You won't think of tables the same way any more and the performance gains will take you by surprise. 😀
October 31, 2013 at 7:49 am
Ed Wagner (10/29/2013)
Luis Cazares (10/29/2013)
If you're looking for ideas, this phrase by Jeff Moden might help you.First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
To expand on what Luis said, I'd like to add a warning: Once you move to set-based code and tally tables, you'll never want to go back. You won't think of tables the same way any more and the performance gains will take you by surprise. 😀
+1 on that! It takes a different way of thinking, breaking the norm.... Try it, you will like it! 😀
Kurt
Kurt W. Zimmerman
SR DBA
Lefrak Organization
New York, NY
http://www.linkedin.com/in/kurtwzimmerman
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply