I don't have the appropriate tables, but try this.
DELIMITER $$
DROP PROCEDURE IF EXISTS `test`.`sp_total_utilization_snapshot_report` $$
CREATE PROCEDURE `test`.`sp_total_utilization_snapshot_report`
(startingWeek datetime, employeeid int)
BEGIN
-- Insert statements for procedure here
CREATE TEMPORARY TABLE IF NOT EXISTS temp_projects
select b.projectname, b.projectid, a.employeeid, c.fname + '' '' + c.lname as EmployeeName, d.role, a.taskDate, b.isBillable, c.showUtilization
from td_projectsTasks a join td_projects b on a.projectid=b.projectid
join td_Employees c on a.employeeid=c.employeeid
join td_Roles d on a.roleid=d.roleid
where a.taskDate >= startingWeek and c.showUtilization = 1
order by b.projectname;
CREATE TEMPORARY TABLE IF NOT EXISTS temp_hoursProposed
select
distinct a.projectid, a.employeeid, b.isBillable, b.showUtilization,
Case When (a.taskDate = startingWeek) Then hoursProposed Else 0 End `Week1`,
Case When (a.taskDate = adddate(startingWeek,7)) Then hoursProposed Else 0 End `Week2`,
Case When (a.taskDate = adddate(startingWeek,14)) Then hoursProposed Else 0 End `Week3`,
Case When (a.taskDate = adddate(startingWeek,21)) Then hoursProposed Else 0 End `Week4`,
Case When (a.taskDate = adddate(startingWeek,28)) Then hoursProposed Else 0 End `Week5`,
Case When (a.taskDate = adddate(startingWeek,35)) Then hoursProposed Else 0 End `Week6`,
Case When (a.taskDate = adddate(startingWeek,42)) Then hoursProposed Else 0 End `Week7`,
Case When (a.taskDate = adddate(startingWeek,49)) Then hoursProposed Else 0 End `Week8`,
Case When (a.taskDate = adddate(startingWeek,56)) Then hoursProposed Else 0 End `Week9`,
Case When (a.taskDate = adddate(startingWeek,63)) Then hoursProposed Else 0 End `Week10`,
Case When (a.taskDate = adddate(startingWeek,70)) Then hoursProposed Else 0 End `Week11`,
Case When (a.taskDate = adddate(startingWeek,77)) Then hoursProposed Else 0 End `Week12`
from td_projectsTasks a join temp_projects b on a.projectid=b.projectid;
CREATE TEMPORARY TABLE IF NOT EXISTS temp_hoursProposed2
select
distinct projectid, employeeId, isBillable, showUtilization,
sum(Week1) as Week1,
sum(Week2) as Week2,
sum(Week3) as Week3,
sum(Week4) as Week4,
sum(Week5) as Week5,
sum(Week6) as Week6,
sum(Week7) as Week7,
sum(Week8) as Week8,
sum(Week9) as Week9,
sum(Week10) as Week10,
sum(Week11) as Week11,
sum(Week12) as Week12
from temp_hoursProposed
group by projectid, employeeid, isBillable, showUtilization;
select sum(a.week1) as week1, sum(a.week2) as week2, sum(a.week3) as week3, sum(a.week4) as week4, sum(a.week5) as week5, sum(a.week6) as week6,
sum(a.week7) as week7, sum(a.week8) as week8, sum(a.week9) as week9, sum(a.week10) as week10, sum(a.week11) as week11, sum(a.week12) as week12
from temp_hoursProposed2 a
where employeeid = employeeID;
END $$
DELIMITER ;
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62:





by: dqmqPosted on 2008-01-17 at 16:59:25ID: 20687100
You are correct, the SP is using several temp tables successively to store intermediate results. The final select, however, summarizes one of the temp tables and produces the output result set.
I hope you don't have very many SP's to convert, because there are many differences. I hope you have some good documentation explaining what the SP's are supposed to do and I hope you have staff that are skilled in both languages.