Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2005
»
T-SQL (SS2K5)
»
Compare rows in the same table and group the...
Compare rows in the same table and group the data
Rate Topic
Display Mode
Topic Options
Author
Message
sharonrao123
sharonrao123
Posted Tuesday, September 18, 2012 7:47 PM
SSC Rookie
Group: General Forum Members
Last Login: Sunday, September 23, 2012 7:50 PM
Points: 41,
Visits: 177
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.
Post #1361086
dwain.c
dwain.c
Posted Wednesday, September 19, 2012 1:46 AM
SSCrazy
Group: General Forum Members
Last Login: Today @ 4:32 PM
Points: 2,369,
Visits: 3,246
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.
No loops! No CURSORs! No RBAR! Hoo-uh!
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?
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Are you too recursively challenged?
Splitting strings based on patterns can be fast!
Post #1361173
sharonrao123
sharonrao123
Posted Wednesday, September 19, 2012 5:33 PM
SSC Rookie
Group: General Forum Members
Last Login: Sunday, September 23, 2012 7:50 PM
Points: 41,
Visits: 177
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.
Post #1361696
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.