Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- +-------------------------------------------------------------------+
- |Route |Sequence| Planned Time | Business Date |
- +-------------------------------------------------------------------+
- | 10-1 | 1 | 2015-08-21 20:15:00.000 | 2015-08-21 |
- | 10-1 | 2 | 2015-08-22 00:30:00.000 | 2015-08-21 |
- | 10-1 | 3 | 2015-08-22 08:45:00.000 | 2015-08-21 |
- | 22-1 | 1 | 2015-08-20 17:30:00.000 | 2015-08-20 |
- | 22-1 | 2 | 2015-08-21 01:10:00.000 | 2015-08-20 |
- | 22-1 | 3 | 2015-08-21 06:30:00.000 | 2015-08-20 |
- +------+--------+---------------------------+-----------------------+
- SELECT
- [Route],
- [Sequence] = ROW_NUMBER() OVER
- (PARTITION BY [Route] ORDER BY [Planned Time]),
- [Planned Time],
- [Business Date] = MIN(CONVERT(DATE, [Planned Time])) OVER
- (PARTITION BY [Route])
- FROM dbo.table_name
- ORDER BY [Route], [Sequence];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement