palmer9
asked on
Help with calculation
Can someone tell me how to divide the results of the two "types" in this query?
I need the result to be Terminated/Budgeted. Right now, I get this:
51314.81 Budgeted
192 Terminated
I another row to show .04% as the percentage.
I need the result to be Terminated/Budgeted. Right now, I get this:
51314.81 Budgeted
192 Terminated
I another row to show .04% as the percentage.
SELECT SUM(ISNULL(ApprovedHrsPerPeriod, 0)) AS Hours, 'Budgeted' AS TYPE
FROM PpPositionDictionary
WHERE (Payroll = 'reg') AND (Active = 'y')
UNION
SELECT SUM(ISNULL(HoursPerPeriod, 0)) AS Hours, 'Terminated' AS TYPE
FROM PPPEREmpPositionFields
WHERE (StatusDate BETWEEN @From AND @Thru) AND (Status = 'TERM') AND (PositionNumber LIKE '%B')
I think that you want to do something like this, instead of union. Just make sure both values are decimal, not integer.
Greg
Greg
SELECT
(SELECT SUM(ISNULL(HoursPerPeriod, 0)) AS Hours, 'Terminated' AS TYPE
FROM PPPEREmpPositionFields
WHERE (StatusDate BETWEEN @From AND @Thru) AND (Status = 'TERM') AND (PositionNumber LIKE '%B')) /
(SELECT SUM(ISNULL(ApprovedHrsPerPeriod, 0)) AS Hours, 'Budgeted' AS TYPE
FROM PpPositionDictionary
WHERE (Payroll = 'reg') AND (Active = 'y')) AS Percentage
ASKER
matthewspatrick -tried this one and get an error : Unable to parse query text...
Incorrect syntax near '/'
JestersGrind - get this error: Only one expression can be specified in the select list when the subquery is not instroduced with EXISTS.
I am writing in Visual Studio 2005 - not sure I can use EXISTS there???
Incorrect syntax near '/'
JestersGrind - get this error: Only one expression can be specified in the select list when the subquery is not instroduced with EXISTS.
I am writing in Visual Studio 2005 - not sure I can use EXISTS there???
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect! Thank you!!
FROM PpPositionDictionary
WHERE (Payroll = 'reg') AND (Active = 'y')
UNION
SELECT SUM(ISNULL(HoursPerPeriod,
FROM PPPEREmpPositionFields
WHERE (StatusDate BETWEEN @From AND @Thru) AND (Status = 'TERM') AND (PositionNumber LIKE '%B')
UNION
(SELECT SUM(ISNULL(ApprovedHrsPerP
FROM PpPositionDictionary
WHERE (Payroll = 'reg') AND (Active = 'y')) /
(SELECT SUM(ISNULL(HoursPerPeriod,
FROM PPPEREmpPositionFields
WHERE (StatusDate BETWEEN @From AND @Thru) AND (Status = 'TERM') AND (PositionNumber LIKE '%B')) AS Hours, 'Perc' AS Type