Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Compare rows in the same table and group the data


Compare rows in the same table and group the data

Author
Message
sharonrao123
sharonrao123
Valued Member
Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)

Group: General Forum Members
Points: 66 Visits: 205
Hello All,

Please point me in the right direction as to where i can start to resolve this problem.

I have a table , below is the dummy data and the desired result.

I need to group the data based on the ProductID, Date,LinesTotal, LinesOutOfService.

I need to check each row in the table to see for that particular product has the different range of values for totallines and Linesoutofservice when compared to the rows below if yes then insert that date where a different range is encountered into the "End Date" column. If no change in the values are detected then insert a future date something like 01/12/2050.

Data

ProductID Date TotalLines LinesOutOfService
522 5/04/2010 345 5
522 6/04/2010 345 5
522 7/04/2010 120 4
522 8/04/2010 345 5
522 9/04/2010 345 5
522 10/04/2010 345 5
522 11/04/2010 117 20
522 12/04/2010 345 5
522 14/04/2010 345 5
522 15/04/2010 260 10
522 16/04/2010 345 5
522 17/04/2010 345 5
522 19/04/2010 345 5


Result

ProductID Start Date End Date TotalLines LinesOutOfService
522 5/04/2010 6/04/2010 345 5
522 7/04/2010 7/04/2010 120 4
522 8/04/2010 10/04/2010 345 5
522 11/04/2010 11/04/2010 117 20
522 12/04/2010 14/04/2010 345 5
522 15/04/2010 15/04/2010 260 10
522 16/04/2010 01/12/2050 345 5


Thanks in advance for your time and suggestions.
dwain.c
dwain.c
SSCarpal Tunnel
SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)

Group: General Forum Members
Points: 4249 Visits: 6431
You might want to take a look at this article by Jeff Moden to get you started: http://www.sqlservercentral.com/articles/T-SQL/71550/, although that endpoint requirement is a bit odd and may take some workarounds.


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
sharonrao123
sharonrao123
Valued Member
Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)Valued Member (66 reputation)

Group: General Forum Members
Points: 66 Visits: 205
Hi dwain,

The link help me to reach a solution.
I have used the SAP Data services History Transform and acheived the desired result.

Thanks, Shilpa.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search