Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

How to Compare Rows within Partitioned Sets to Find Overlapping Dates Expand / Collapse
Author
Message
Posted Monday, October 11, 2010 10:13 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, April 23, 2013 6:01 PM
Points: 9, Visits: 319
David McKinney (10/11/2010)
Shouldn't you have a LEFT JOIN rather than an INNER JOIN?


You're right! In haste, I ran an INNER JOIN so that I could just see the compared rows, but in hindsight, I probably should have kept my base table pure and ran a LEFT JOIN instead. This at least would have allowed me to keep my table counts the same as well as singling out the last row in each partitioned set.
Post #1002309
Posted Monday, October 11, 2010 10:25 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, April 23, 2013 6:01 PM
Points: 9, Visits: 319
ta.bu.shi.da.yu (10/11/2010)
If I read this correctly, you just implemented the LAG(...) Over(...) analytic function.


Cool, I didn't even know this existed. But it looks like it's only available in Oracle databases. Microsoft, please bring this over!

However, I'm interested... if you do this on a large dataset, what does the execution plan look like?


Let me try to get my execution plan and I'll get back to you. I do remember that our initial process ran painfully slow and we had just 45K rows. It ran for something like 45 seconds (almost 1 sec/1K rows) using a scalar function. This updated process now takes less than one second to complete.
Post #1002320
Posted Tuesday, October 12, 2010 3:53 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, May 22, 2013 9:04 AM
Points: 16, Visits: 107
Real World Example: Wage and Hour Class Action Lawsuits. I am always working with dates on employment cases and many times the individual has many start and end dates. Part of the scrubbing process is to check for date overlaps or gaps. This is a good start to check those types of things.

Thanks for the post! :)
Post #1003261
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse