You can use a CASE statement to group your data.
two queries summing into a single value
Collapse
X
-
Rabbit,
With using CASE, wouldn't I have to do that in my first query? Because after that I've summed for "spec minutes" and because in the end, these things are broken out as individual elements rather than just a sum value. Or am I thinking incorrectly?Comment
-
I don't know which level you would have to group your data at because I have no idea what your queries look like. You supplied two queries in the original question but from the sample results you've shown me, they have no connection to those queries. Plus, you've probably made changes and I have no idea as to what the current queries look like.Comment
-
Rabbit,
The sample results come from this query:
SELECT DISTINCT
[ScratchPad5].EmployeeNumber ,
SUM( case when [sumhours]>40
THEN 40
ELSE cast([sumhours] as numeric(12,2))
END ) AS TotalRegHours,
SUM( case when [sumhours]>40
THEN cast([sumhours]-40 as numeric(12,2))
ELSE 0
END ) AS TotalOT
into scratchpad7
FROM
ScratchPad5
GROUP BY
[ScratchPad5].EmployeeNumber ,
sumhours
order by employeenumber asc
which produces this result:
Code:Agent Number Regular Time Total O/T 8245 18.01 0
1. To show results like this like post #9 which is sorting all data based on "code" in my table and showing them to the user.
2. If the "code" doesnt match ETO, Vacation, Sick Time then it will be a Misc, which is then summed.Comment
-
Rabbit,
In my first query you'll notice that I have this:
SELECT s1.Employeenumb er, s1.[Name], s2.Exceptiondat e, code, s2.totalminutes into scratchpad4
FROM
(select distinct Employeenumber,[Name] from Scratchpad1) AS s1
inner JOIN
(select employeenumber, exceptiondate, code, sum(duration) as totalminutes
from scratchpad3
where exceptiondate between @payrollstartda te And @payrollenddate
group by employeenumber, exceptiondate, code) as s2
ON s1.Employeenumb er = s2.Employeenumb er
order by exceptiondate ascComment
Comment