sql server 2005 - TSQL: Datetime overlapping and interval values -


Need help creating a query for this.

  get started. End 2009-01-01 06:00:00 | 2009-01-01 14:00:00 2009-01-01 06:00:00 | 2009-01-02 06:00:00 2009-01-02 07:00:00 | 2009-01-02 08:00:00 2009-01-03 06:00:00 | 2009-01-03 14:00:00 2009-01-03 09: 00: 00 2009-01-03 11:00:00 2009-01-04 22: 00:00 | 2009-01-05 06:00:00 2009-01-05 01:00:00 | 2009-01-05 10:00:00  

I want to get un-overlap time for the interval ( 2009-01-01 00:00:00 - 2009-01-31 00:00:00 ) with Yoga for each day:

  Date | Duration 2009-01-01 | 18 2009-01-02 | 7 2009-01-03 | 8 2009-01-04 | 2 2009-01-05 |   

itemprop = "text">

Try it:

 with  in the form of times (select the interval (interval) for the interval from time to select the unius all ([end]) as the interval of time, Times (select date time, date, date, 0, time)) as times (times in the form of Times) (select time from time to time all time select time) Times 3 Select ROW_NUMBER () timely (according to time), ta Times 2 times from Ms), Times 4 AS (Started as SELECT T1.Time, T2. Time 3 T1 JOINT TIMES 3 T2 ON T1. RN + 1 = T2.rn from [closing] as time. ), Intervalparts (Select Times 4. * Add interval to Times 4 from Times 4. Start & gt; = Interval. Start & Times 4. [And] End Lieutenant; = Interval. [End], Interwalsby AS ( Select day (DD, 0, DATEDIFF (DD, 0, Start)), DATEDIFF (HH, Start, [end]) Duration Period Choose SUM (Period) BD Day Group from AS Period Interval  

Result:

  Duration of the day 2009-01-01 00: 00 : 00.000 18 2009-01-02 00: 00: 00.000 7 2009-01-03 00: 00: 00.000 8 2009-01-04 00: 00: 00.000 2 2009-01-05 00: 00: 00.000 10  

To limit it to a certain extent, just add one appropriate WHERE segment.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -