Author |
Topic |
dougancil
Posting Yak Master
217 Posts |
Posted - 2010-11-23 : 15:24:26
|
I have the following query:SELECT DISTINCT [ScratchPad5].EmployeeNumber, Sum([ScratchPad5].sumhours),case when [sumhours]>40 THEN [sumhours]-40 ELSE 0 END AS ot, case when [sumhours]>40 THEN [sumhours]-[ot] ELSE [sumhours] END AS RegHoursFROM ScratchPad5GROUP BY [ScratchPad5].EmployeeNumber, sumhours, otand the result set that it is giving me is this:Employeenumber (No Column Name) ot RegHours8247 23.683166 .000000 23.6831668330 3.000000 .000000 3.0000008378 29.226166 .000000 29.2261668389 27.221166 .000000 27.2211668428 32.371000 .000000 32.3710008433 31.898833 .000000 31.8988338442 29.853500 .000000 29.8535008454 17.349500 .000000 17.3495008455 25.910500 .000000 25.9105008462 35.770833 .000000 35.7708338464 38.410332 .000000 19.2051668465 30.944500 .000000 30.9445008466 29.450666 .000000 29.4506668467 51.734000 11.734000 NULLand it what I'm needing it to do is for entries like the last one, to show me both the total time worked (No Column Name) and the OT but then it should show 40 hours for Reg Hours. Can anyone please assist with this?ThanksDoug |
|
X002548
Not Just a Number
15586 Posts |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-11-24 : 10:02:41
|
are you sure query you posted is working one?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
dougancil
Posting Yak Master
217 Posts |
Posted - 2010-11-24 : 15:38:22
|
I am sure that it works. The result set is the results that I got from the query being ran. |
|
|
X002548
Not Just a Number
15586 Posts |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-11-26 : 10:30:38
|
See if this worksSELECT [ScratchPad5].EmployeeNumber, Sum([ScratchPad5].sumhours),case when [sumhours]>40 THEN [sumhours]-40 ELSE 0 END AS ot, case when [sumhours]>40 THEN [sumhours]-coalesce([ot],0) ELSE [sumhours] END AS RegHoursFROM ScratchPad5GROUP BY [ScratchPad5].EmployeeNumber, sumhours, otMadhivananFailing to plan is Planning to fail |
|
|
dougancil
Posting Yak Master
217 Posts |
Posted - 2010-11-29 : 11:04:56
|
Madhivanan,Here is the one line of my results that I'm using as my "benchmark" to see if this works or not:Employeenumber (No column name) ot Regular Hours8467 51.734000 11.734000 51.734000and what this should have for Regular Hours is 40 hours. As you can see from the query that you provided, that it shows me the total number of hours, not just the total number of "regular hours." Does that make sense?Thank youDoug |
|
|
dougancil
Posting Yak Master
217 Posts |
Posted - 2010-12-03 : 12:37:56
|
Can anyone else offer any help with this?Thank youDoug |
|
|
dougancil
Posting Yak Master
217 Posts |
Posted - 2010-12-10 : 14:23:19
|
Just as an fyi, here is the correct way that this query had to be written:SELECT DISTINCT [ScratchPad5].EmployeeNumber, Sum([ScratchPad5].sumhours), SUM( case when [sumhours]>40 THEN [sumhours]-40 ELSE 0 END ) AS TotalOT, SUM( case when [sumhours]>40 THEN 40 ELSE [sumhours] END ) AS TotalRegHoursFROM ScratchPad5GROUP BY [ScratchPad5].EmployeeNumber, sumhours, ot |
|
|
|