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 |
teknomec
Starting Member
4 Posts |
Posted - 2012-02-16 : 04:03:59
|
I have table values like below.JOBNUMBER ACTIVITYTIME STATUS ENGINEER1789 2011-12-27 14:56:29.000 Left for site 501789 2011-12-27 14:56:42.000 Reached the site 501789 2011-12-27 15:07:46.000 Work started 501789 2012-01-11 12:29:11.000 Held for Other Reasons 50I need to calculate values like belowJobnumber Traveltime(Activitytime) Worktime Employee1789 Reached the site - Left for site Workstarted - Held for Other Reasons 50To calculate traveltime i need to subtract Acivitytime between Left for site and Reached the site.To calculate work time i need to subtract Activity time between Workstarted and held for other reasons |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-02-16 : 04:10:22
|
The Status is in text or do you have a status code ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
teknomec
Starting Member
4 Posts |
Posted - 2012-02-16 : 04:13:37
|
It is a standard text. |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-02-16 : 04:33:49
|
[code]select JOBNUMBER, Traveltime = convert(varchar(10), dateadd(second, datediff(second, min(case when STATUS = 'Left for site' then ACTIVITYTIME end), min(case when STATUS = 'Reached the site' then ACTIVITYTIME end) ), 0), 108), Worktime = convert(varchar(10), dateadd(second, datediff(second, min(case when STATUS = 'Work started' then ACTIVITYTIME end), min(case when STATUS = 'Held for Other Reasons' then ACTIVITYTIME end) ), 0), 108), Employee = ENGINEERfrom yourtablegroup by JOBNUMBER, ENGINEER[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
teknomec
Starting Member
4 Posts |
Posted - 2012-02-16 : 05:14:48
|
Thanks for the reply. when i run the query i get null values like.1789 NULL NULL 501795 NULL NULL 50should i do any other modification in the query. |
 |
|
|
|
|
|
|