| Author |
Topic |
|
yosiasz
Master Smack Fu Yak Hacker
1635 Posts |
Posted - 2008-06-30 : 12:22:27
|
| Hi,Given the following tablesJobs (JobID, ShiftID, EquipmentID, StartTime, EndTime)Shift (ShiftID, ShiftName, StartTime, EndTime)Equipment (EquipmentID, EquipmentDescr)I would appreciate your help in doing a pivot query to get following resultsEquipmentDescr | ShiftName | ShiftTotal Hours | Shift Assigned Hours Saw #1 | Shift 1 | 300 | 250ShiftTotal Hours is the sum of the hours/minutes of that shift Shift Assigned Hours is the sum of jobs assigned to a specific shift and on specific equipmentThanks!!! |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-30 : 12:51:12
|
| will be you be using a single equipment for a job? |
 |
|
|
yosiasz
Master Smack Fu Yak Hacker
1635 Posts |
Posted - 2008-06-30 : 13:19:49
|
| Yes single equipment and single shift |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-30 : 13:32:44
|
quote: Originally posted by yosiasz Yes single equipment and single shift
SELECT e.EquipmentDescr , s.ShiftName,SUM(DATEDIFF(ss,s.StartTime, s.EndTime))/60 AS [ShiftTotal Hours],j.[Shift Assigned Hours]FROM Shift sINNER JOIN (SELECT ShiftID, SUM(DATEDIFF(ss,j.StartTime, j.EndTime))/60 AS Shift Assigned HoursFROM Jobs GROUP BY ShiftID)jON j.ShiftID=s.ShiftIDINNER JOIN Equipment eON e.EquipmentID=j.EquipmentIDGROUP BY e.EquipmentDescr , s.ShiftName |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
|
|
yosiasz
Master Smack Fu Yak Hacker
1635 Posts |
Posted - 2008-06-30 : 14:03:18
|
| Thanks very much !!!! this is very nice. but how do I pivot this in order to see it as followsItems in bracket are just FYI ... {EquipmentDescr | ShiftName | ShiftTotal Hours | Shift Assigned Hours } Saw #1 | Shift 1 | 300 | 250Much obliged |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-01 : 01:11:56
|
quote: Originally posted by yosiasz Thanks very much !!!! this is very nice. but how do I pivot this in order to see it as followsItems in bracket are just FYI ... {EquipmentDescr | ShiftName | ShiftTotal Hours | Shift Assigned Hours } Saw #1 | Shift 1 | 300 | 250Much obliged
Didint get that. are you telling you want them to be column headers? |
 |
|
|
yosiasz
Master Smack Fu Yak Hacker
1635 Posts |
Posted - 2008-07-01 : 10:13:18
|
| Hi Visakh. yes I wanted them to be table heads. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-01 : 13:35:50
|
quote: Originally posted by yosiasz Hi Visakh. yes I wanted them to be table heads.
then what will be data shown under each column? |
 |
|
|
|