## Set based super challenge

 Author Message dwain.c SSCarpal Tunnel Group: General Forum Members Points: 4249 Visits: 6431 ChrisM@Work (12/12/2013)`-- I might give it a go over lunch.----------------------------------------------------------------------------------------`I can see it now. Cornish pasty in one hand while the other furiously types in the 1M row test harness.Mmmm, mmmm! :-P 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 lotusnotes SSC Rookie Group: General Forum Members Points: 45 Visits: 217 Thanks Chris. I think you have done enough already :-) ChrisM@Work SSCrazy Eights Group: General Forum Members Points: 8962 Visits: 19020 dwain.c (12/12/2013)ChrisM@Work (12/12/2013)`-- I might give it a go over lunch.----------------------------------------------------------------------------------------`I can see it now. Cornish pasty in one hand while the other furiously types in the 1M row test harness.Mmmm, mmmm! :-PGood Lord no Dwain, I'd use one of Jeff's fancy shmancy tally tables!! “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail ShawFor fast, accurate and documented assistance in answering your questions, please read this article.Understanding and using APPLY, (I) and (II) Paul White Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff ModenExploring Recursive CTEs by Example Dwain Camps ChrisM@Work SSCrazy Eights Group: General Forum Members Points: 8962 Visits: 19020 dwain.c (12/11/2013)Jeff Moden (12/11/2013)ChrisM@Work (12/11/2013)Gosh, I'm surprised that with a title like this, there have been so few takers - and so little feedback from the OP. Maybe those sleepless nights have caught up. Here's a simple solution for starters.I don't know what's going on with the OP but when I see that ChrisM has worked a problem, I figure there's little left for me to do and move on. ;-)I feel the same way! :-DI did look at this thread yesterday and saw that Chris suggested there was something wrong with the sample data/results so I passed on it at the time.That's 'cos I always pick the easy ones:-P “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail ShawFor fast, accurate and documented assistance in answering your questions, please read this article.Understanding and using APPLY, (I) and (II) Paul White Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff ModenExploring Recursive CTEs by Example Dwain Camps