Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase «««123

Querying a Supersession Two Column Table with Multiple Supersessions in both Columns Expand / Collapse
Posted Tuesday, February 4, 2014 7:17 PM

Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Wednesday, February 24, 2016 6:28 AM
Points: 3,977, Visits: 6,431
I'm just guessing here because I don't have much additional time to look deeper, but this probably has to do with the fact you have no "supersession date" on your Supersessions table (recall I mentioned this earlier).

If you look at the code I provided (the last query), you see I'm jumping through quite a few hoops to try and get a reasonable sort order that places earlier part numbers before later ones. What I did there is far from perfect and probably leads you to situations like this. In effect, there is no way to determine the order that part numbers get retired/replaced. Ultimately I think you'll need that to get a good list of supersession parts in an appropriate sequence.

My mantra: No loops! No CURSORs! No RBAR! Hoo-uh!

My thought question: Have you ever been told that your query runs too fast?

My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Learn to understand recursive CTEs by example.
Splitting strings based on patterns can be fast!
My temporal SQL musings: Calendar Tables, an Easter SQL, Time Slots and Self-maintaining, Contiguous Effective Dates in Temporal Tables
Post #1538018
Posted Wednesday, February 5, 2014 7:59 PM



Group: General Forum Members
Last Login: Yesterday @ 9:09 PM
Points: 42,046, Visits: 39,429
Sorry. Bad post deleted. I had a question on the order of things but figured that out. Order doesn't seem to matter here.

--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

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."

Helpful Links:
How to post code problems
How to post performance problems
Post #1538448
« Prev Topic | Next Topic »

Add to briefcase «««123

Permissions Expand / Collapse