December 8, 2014 at 9:53 am
Hi
This is a question from a high level view about the possibility of removing a cursor from some of our tsql code.
Basically the steps are:
We create a temporary table, we open a cursor and fetch a number of input variables from various tables which are then pasted to a stored procedure and executed - the cursor then fetches the next lot of parameters fro input into the stored proc.
Could a CTE be used in this situation to do the same ?
December 8, 2014 at 10:17 am
Your main problem is the stored procedure. Unless you change the code from the procedure, you'll end up with RBAR anyway.
December 8, 2014 at 2:39 pm
You could build a concatenated string containing all the executions, then EXEC() that string. The issue would be if errors occurred during processing.
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
December 8, 2014 at 6:34 pm
PearlJammer1 (12/8/2014)
HiThis is a question from a high level view about the possibility of removing a cursor from some of our tsql code.
Basically the steps are:
We create a temporary table, we open a cursor and fetch a number of input variables from various tables which are then pasted to a stored procedure and executed - the cursor then fetches the next lot of parameters fro input into the stored proc.
Could a CTE be used in this situation to do the same ?
If you have a stored procedure that needs to be fed one set of parameters at a time, then you're considering fixing the wrong problem. The stored procedure needs to be fixed, not the cursor. There is no disadvantage to using a cursor for this particular task and a well written cursor will usually perform just as well or sometimes better than the use of explicit temp tables to do the same thing.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply