JMac
2012-08-22 15:16:31 UTC
I have a SQL 2008 table called linefaultdata that contains the following data
ID FaultCode AssetID StartTime Duration Shift
2670376 8 2 2011-08-19 19:20:30.000 14 AFTERNOONS
2670608 7 2 2011-08-19 21:10:24.000 12 AFTERNOONS
2671183 8 2 2011-08-19 01:10:36.000 22 NIGHTS
2671467 2 2 2011-08-19 03:20:34.000 12 NIGHTS
2672351 3 2 2011-08-19 09:10:30.000 19 DAYS
2673047 3 2 2011-08-19 13:10:45.000 19 DAYS
2675476 8 2 2011-08-19 14:14:54.000 23 DAYS
2678765 7 2 2011-08-19 01:23:43.000 19 NIGHTS
2678654 8 2 2011-08-19 20:01:03.000 21 AFTERNOONS
I'm looking to create a query that would group the data by FaultCode and Shift and by defined time periods in each shift. Here is an example of what I would like to see.
Shift Time Code Count Sum Of Duration
Nights 11pm - 12am
Nights 12am - 1am
Nights 1am - 2am 7 1 19
8 1 22
Nights 2am - 3am
Nights 3am - 4am 2 1 12
Nights 4am - 5am
Nights 5am - 6am
Nights 6am - 7am
Days 7am - 8am
Days 8am - 9am
Days 9am - 10am 3 1 19
Days 11am - 12pm
Days 12pm - 1pm
Days 1pm - 2pm 3 1 19
Days 2pm - 3pm 8 1 23
Afternoons3pm - 4pm
Afternoons4pm - 5pm
Afternoons5pm - 6pm
Afternoons6pm - 7pm
Afternoons7pm - 8pm 8 1 14
Afternoons8pm - 9pm 8 1 21
Afternoons9pm - 10pm 7 1 12
Afternoons10pm - 11pm
Any help would be appreciated.
Thanks
ID FaultCode AssetID StartTime Duration Shift
2670376 8 2 2011-08-19 19:20:30.000 14 AFTERNOONS
2670608 7 2 2011-08-19 21:10:24.000 12 AFTERNOONS
2671183 8 2 2011-08-19 01:10:36.000 22 NIGHTS
2671467 2 2 2011-08-19 03:20:34.000 12 NIGHTS
2672351 3 2 2011-08-19 09:10:30.000 19 DAYS
2673047 3 2 2011-08-19 13:10:45.000 19 DAYS
2675476 8 2 2011-08-19 14:14:54.000 23 DAYS
2678765 7 2 2011-08-19 01:23:43.000 19 NIGHTS
2678654 8 2 2011-08-19 20:01:03.000 21 AFTERNOONS
I'm looking to create a query that would group the data by FaultCode and Shift and by defined time periods in each shift. Here is an example of what I would like to see.
Shift Time Code Count Sum Of Duration
Nights 11pm - 12am
Nights 12am - 1am
Nights 1am - 2am 7 1 19
8 1 22
Nights 2am - 3am
Nights 3am - 4am 2 1 12
Nights 4am - 5am
Nights 5am - 6am
Nights 6am - 7am
Days 7am - 8am
Days 8am - 9am
Days 9am - 10am 3 1 19
Days 11am - 12pm
Days 12pm - 1pm
Days 1pm - 2pm 3 1 19
Days 2pm - 3pm 8 1 23
Afternoons3pm - 4pm
Afternoons4pm - 5pm
Afternoons5pm - 6pm
Afternoons6pm - 7pm
Afternoons7pm - 8pm 8 1 14
Afternoons8pm - 9pm 8 1 21
Afternoons9pm - 10pm 7 1 12
Afternoons10pm - 11pm
Any help would be appreciated.
Thanks