Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
the_justin
Starting Member
19 Posts |
Posted - 2009-03-08 : 20:49:09
|
| Hi all,I have a table similar to this:timecode datestart dateend totalweightA 07:00 07:02 2A 07:20 07:21 1A 07:30 07:32 3B 07:05 07:06 2B 07:07 07:09 2B 07:40 07:41 1now i'm aiming to create a table like this from the above tableA 07:00 07:02 2B 07:05 07:09 4 -- this is from 07:05-07:06 and 07:07-7:09A 07:20 07:32 4 -- this is from 07:20-07:21 and 07:30-07:32B 07:40 07:41 1anyone have an idea of how to do this ? Thank you in advance |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-03-08 : 21:06:04
|
| What is the criteria of startdate and enddate that defines SUM or not SUM ? |
 |
|
|
the_justin
Starting Member
19 Posts |
Posted - 2009-03-08 : 21:30:19
|
| hi sodeep, thanks for replying, the aggregation is base on the timecode and timeline.so in the mentioned example, first sort it by datestart to be like this:A 07:00 07:02 2B 07:05 07:06 2 B 07:07 07:09 2A 07:20 07:21 3 A 07:30 07:32 1B 07:40 07:41 1then from here, to this:A 07:00 07:02 2B 07:05 07:09 4 A 07:20 07:32 4 B 07:40 07:41 1hope this makes sense to you.Thank you |
 |
|
|
the_justin
Starting Member
19 Posts |
Posted - 2009-03-08 : 22:10:26
|
| got the answer. using SELECT CN = ROW_NUMBER() OVER (ORDER BY datestart) - ROW_NUMBER() OVER (PARTITION BY timecode ORDER BY datestart), timecode, datestart, dateend, totalweight FROM @datathis article will explain it:http://www.sqlmag.com/Article/ArticleID/93606/sql_server_93606.htmlthanks to everyone reading this and specially andrewd.smith. |
 |
|
|
|
|
|