August 1, 2008 at 11:11 am
;WITH emps(empID,Percent)
AS
(
SELECT
empID,
case when COUNT(DISTINCT payid)>4 then (COUNT(DISTINCT payid)/5)*100
else (COUNT(DISTINCT payid)/4)*100
end
FROM
paytbl INNER JOIN
#tmpemp ON #tmpemp.Value = paytbl.empId
)
select * from emps
I am not getting the floating number for percent. How could i make my percent as float datatype in CTE?
August 1, 2008 at 11:28 am
When you divide an integer by an integer, you get an integer. Change the /5 and /4 to be /5.0 and /4.0 and you should get a float.
August 1, 2008 at 5:18 pm
DECLARE @Month int
set @Month=1
;WITH emps(empID)
AS
(
SELECT empID FROM
#tmpemp
)
select @month,hours
from emps inner join hours
on emps.empid=hours.empid
I get only for 1 month from this query, how would i calcualte for all 12 months. i can do it through cursor but how abt CTE?
something like @Month+1 upto 12.
August 1, 2008 at 8:09 pm
This is why we always ask for a description of what you're trying to do... are you trying to generate 12 otherwise identical rows for each employee or ???
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply