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 |
Brittney10
Posting Yak Master
154 Posts |
Posted - 2013-01-22 : 10:31:37
|
I'm trying to determine the date difference between two records. For example:ID_____TYPE______TIME1______START____1/22/2013 08:00:00AM1______END______1/22/2013 08:10:00AM2______START____1/22/2013 09:00:00AM2______END______1/22/2013 09:20:00AMRESULTSID____DIFF1_____00:00:102_____00:00:20Basically the difference between start and end time group by ID. Thanks for the help in advance! |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-01-22 : 10:47:06
|
If the time column is datetime type, then:SELECT id, CONVERT( VARCHAR(32), MAX(CASE WHEN TYPE = 'end' THEN TIME END)- MIN(CASE WHEN TYPE = 'start' THEN TIME END) ,114)FROM YourTableGROUP BY id |
|
|
Brittney10
Posting Yak Master
154 Posts |
Posted - 2013-01-22 : 11:52:12
|
Perfect! Exactly what i was trying to accomplish. Thanks! |
|
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-01-22 : 13:02:34
|
You are very welcome - glad to be of help. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-23 : 01:33:27
|
quote: Originally posted by Brittney10 Perfect! Exactly what i was trying to accomplish. Thanks!
can there be a data like below5______START____1/22/2013 09:00:00PM5______END______1/23/2013 03:20:00AM------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|