I built this stored procedure with help from this group. It may not be the
most efficient but it works for me.
CREATE PROCEDURE [dbo].[USP_MSPA_ALL_TASK_TIME_BY_RESOURCE_FOR_DATE_RANGE]
@Res_Name as varchar(50) ,
@Begin_Date as DateTime,
@End_Date as DateTime
AS
Begin
SELECT w1.res_name as Lead, p.PROJ_NAME as Project, r.RES_NAME as
Resource, a.TASK_NAME as Task, a.ASSN_ACT_WORK / 60000 AS actual_hours,
a.ASSN_START_DATE AS start_date,
a.ASSN_FINISH_DATE AS finish_date, a.ASSN_WORK / 60000
AS assigned_work, a.ASSN_REM_WORK / 60000 AS remaining_work,
a.WASSN_LAST_WORK / 60000 AS assigned_last_work,
a.WASSN_SEND_UPDATE_DATE AS update_sent_date, (w.wwork_value) / 60000 AS
[work],
w.wwork_start AS work_date, w.wwork_start as
work_start, w.wwork_finish as work_finish
FROM dbo.MSP_WEB_RESOURCES r INNER JOIN
dbo.MSP_WEB_ASSIGNMENTS a ON a.WRES_ID = r.WRES_ID
INNER JOIN
dbo.MSP_WEB_PROJECTS p ON p.WPROJ_ID = a.WPROJ_ID
INNER JOIN
dbo.MSP_WEB_WORK w ON a.WASSN_ID = w.WASSN_ID
LEFT JOIN dbo.MSP_WEB_RESOURCES w1 ON a.WRES_ID_MGR = w1.WRES_ID
WHERE w.wwork_type = 1 AND w.wwork_value > 0
and r.Res_Name like @res_name
and w.wwork_start between @Begin_Date and @End_Date
UNION
SELECT w1.res_name as Lead, p.PROJ_NAME, r.RES_NAME, a.TASK_NAME,
a.ASSN_ACT_WORK / 60000 AS actual_hours, a.ASSN_START_DATE AS start_date,
a.ASSN_FINISH_DATE AS finish_date, a.ASSN_WORK / 60000
AS assigned_work, a.ASSN_REM_WORK / 60000 AS remaining_work,
a.WASSN_LAST_WORK / 60000 AS assigned_last_work,
a.WASSN_SEND_UPDATE_DATE AS update_sent_date, (w.wwork_value) / 60000 AS
[work],
DateAdd(d, 1, w.WWORK_START) AS work_date,
w.wwork_start, w.wwork_finish
FROM dbo.MSP_WEB_RESOURCES r INNER JOIN
dbo.MSP_WEB_ASSIGNMENTS a ON a.WRES_ID = r.WRES_ID
INNER JOIN
dbo.MSP_WEB_PROJECTS p ON p.WPROJ_ID = a.WPROJ_ID
INNER JOIN
dbo.MSP_WEB_WORK w ON a.WASSN_ID = w.WASSN_ID
LEFT JOIN dbo.MSP_WEB_RESOURCES w1 ON a.WRES_ID_MGR = w1.WRES_ID
WHERE w.wwork_type = 1 AND w.wwork_value > 0 AND w.WWORK_START <>
w.WWORK_FINISH AND DateAdd(d, 1, w.WWORK_START)
<= w.WWORK_FINISH
and r.Res_Name like @res_name
and w.wwork_start between @Begin_Date and @End_Date
UNION
SELECT w1.res_name as Lead, p.PROJ_NAME, r.RES_NAME, a.TASK_NAME,
a.ASSN_ACT_WORK / 60000 AS actual_hours, a.ASSN_START_DATE AS start_date,
a.ASSN_FINISH_DATE AS finish_date, a.ASSN_WORK / 60000
AS assigned_work, a.ASSN_REM_WORK / 60000 AS remaining_work,
a.WASSN_LAST_WORK / 60000 AS assigned_last_work,
a.WASSN_SEND_UPDATE_DATE AS update_sent_date, (w.wwork_value) / 60000 AS
[work],
DateAdd(d, 2, w.WWORK_START) AS work_date,
w.wwork_start, w.wwork_finish
FROM dbo.MSP_WEB_RESOURCES r INNER JOIN
dbo.MSP_WEB_ASSIGNMENTS a ON a.WRES_ID = r.WRES_ID
INNER JOIN
dbo.MSP_WEB_PROJECTS p ON p.WPROJ_ID = a.WPROJ_ID
INNER JOIN
dbo.MSP_WEB_WORK w ON a.WASSN_ID = w.WASSN_ID
LEFT JOIN dbo.MSP_WEB_RESOURCES w1 ON a.WRES_ID_MGR = w1.WRES_ID
WHERE w.wwork_type = 1 AND w.wwork_value > 0 AND w.WWORK_START <>
w.WWORK_FINISH AND DateAdd(d, 2, w.WWORK_START)
<= w.WWORK_FINISH
and r.Res_Name like @res_name
and w.wwork_start between @Begin_Date and @End_Date
UNION
SELECT w1.res_name as Lead, p.PROJ_NAME, r.RES_NAME, a.TASK_NAME,
a.ASSN_ACT_WORK / 60000 AS actual_hours, a.ASSN_START_DATE AS start_date,
a.ASSN_FINISH_DATE AS finish_date, a.ASSN_WORK / 60000
AS assigned_work, a.ASSN_REM_WORK / 60000 AS remaining_work,
a.WASSN_LAST_WORK / 60000 AS assigned_last_work,
a.WASSN_SEND_UPDATE_DATE AS update_sent_date, (w.wwork_value) / 60000 AS
[work],
DateAdd(d, 3, w.WWORK_START) AS work_date,
w.wwork_start, w.wwork_finish
FROM dbo.MSP_WEB_RESOURCES r INNER JOIN
dbo.MSP_WEB_ASSIGNMENTS a ON a.WRES_ID = r.WRES_ID
INNER JOIN
dbo.MSP_WEB_PROJECTS p ON p.WPROJ_ID = a.WPROJ_ID
INNER JOIN
dbo.MSP_WEB_WORK w ON a.WASSN_ID = w.WASSN_ID
LEFT JOIN dbo.MSP_WEB_RESOURCES w1 ON a.WRES_ID_MGR = w1.WRES_ID
WHERE w.wwork_type = 1 AND w.wwork_value > 0 AND w.WWORK_START <>
w.WWORK_FINISH AND DateAdd(d, 3, w.WWORK_START)
<= w.WWORK_FINISH
and r.Res_Name like @res_name
and w.wwork_start between @Begin_Date and @End_Date
UNION
SELECT w1.res_name as Lead, p.PROJ_NAME, r.RES_NAME, a.TASK_NAME,
a.ASSN_ACT_WORK / 60000 AS actual_hours, a.ASSN_START_DATE AS start_date,
a.ASSN_FINISH_DATE AS finish_date, a.ASSN_WORK / 60000
AS assigned_work, a.ASSN_REM_WORK / 60000 AS remaining_work,
a.WASSN_LAST_WORK / 60000 AS assigned_last_work,
a.WASSN_SEND_UPDATE_DATE AS update_sent_date, (w.wwork_value) / 60000 AS
[work],
DateAdd(d, 4, w.WWORK_START) AS work_date,
w.wwork_start, w.wwork_finish
FROM dbo.MSP_WEB_RESOURCES r INNER JOIN
dbo.MSP_WEB_ASSIGNMENTS a ON a.WRES_ID = r.WRES_ID
INNER JOIN
dbo.MSP_WEB_PROJECTS p ON p.WPROJ_ID = a.WPROJ_ID
INNER JOIN
dbo.MSP_WEB_WORK w ON a.WASSN_ID = w.WASSN_ID
LEFT JOIN dbo.MSP_WEB_RESOURCES w1 ON a.WRES_ID_MGR = w1.WRES_ID
WHERE w.wwork_type = 1 AND w.wwork_value > 0 AND w.WWORK_START <>
w.WWORK_FINISH AND DateAdd(d, 4, w.WWORK_START)
<= w.WWORK_FINISH
and r.Res_Name like @res_name
and w.wwork_start between @Begin_Date and @End_Date
UNION
SELECT w1.res_name as Lead, p.PROJ_NAME, r.RES_NAME, a.TASK_NAME,
a.ASSN_ACT_WORK / 60000 AS actual_hours, a.ASSN_START_DATE AS start_date,
a.ASSN_FINISH_DATE AS finish_date, a.ASSN_WORK / 60000
AS assigned_work, a.ASSN_REM_WORK / 60000 AS remaining_work,
a.WASSN_LAST_WORK / 60000 AS assigned_last_work,
a.WASSN_SEND_UPDATE_DATE AS update_sent_date, (w.wwork_value) / 60000 AS
[work],
DateAdd(d, 5, w.WWORK_START) AS work_date,
w.wwork_start, w.wwork_finish
FROM dbo.MSP_WEB_RESOURCES r INNER JOIN
dbo.MSP_WEB_ASSIGNMENTS a ON a.WRES_ID = r.WRES_ID
INNER JOIN
dbo.MSP_WEB_PROJECTS p ON p.WPROJ_ID = a.WPROJ_ID
INNER JOIN
dbo.MSP_WEB_WORK w ON a.WASSN_ID = w.WASSN_ID
LEFT JOIN dbo.MSP_WEB_RESOURCES w1 ON a.WRES_ID_MGR = w1.WRES_ID
WHERE w.wwork_type = 1 AND w.wwork_value > 0 AND w.WWORK_START <>
w.WWORK_FINISH AND DateAdd(d, 5, w.WWORK_START)
<= w.WWORK_FINISH
and r.Res_Name like @res_name
and w.wwork_start between @Begin_Date and @End_Date
UNION
SELECT w1.res_name as Lead, p.PROJ_NAME, r.RES_NAME, a.TASK_NAME,
a.ASSN_ACT_WORK / 60000 AS actual_hours, a.ASSN_START_DATE AS start_date,
a.ASSN_FINISH_DATE AS finish_date, a.ASSN_WORK / 60000
AS assigned_work, a.ASSN_REM_WORK / 60000 AS remaining_work,
a.WASSN_LAST_WORK / 60000 AS assigned_last_work,
a.WASSN_SEND_UPDATE_DATE AS update_sent_date, (w.wwork_value) / 60000 AS
[work],
DateAdd(d, 6, w.WWORK_START) AS work_date,
w.wwork_start, w.wwork_finish
FROM dbo.MSP_WEB_RESOURCES r INNER JOIN
dbo.MSP_WEB_ASSIGNMENTS a ON a.WRES_ID = r.WRES_ID
INNER JOIN
dbo.MSP_WEB_PROJECTS p ON p.WPROJ_ID = a.WPROJ_ID
INNER JOIN
dbo.MSP_WEB_WORK w ON a.WASSN_ID = w.WASSN_ID
LEFT JOIN dbo.MSP_WEB_RESOURCES w1 ON a.WRES_ID_MGR = w1.WRES_ID
WHERE w.wwork_type = 1 AND w.wwork_value > 0 AND w.WWORK_START <>
w.WWORK_FINISH AND DateAdd(d, 6, w.WWORK_START)
<= w.WWORK_FINISH
and r.Res_Name like @res_name
and w.wwork_start between @Begin_Date and @End_Date
UNION
SELECT w1.res_name as Lead, p.PROJ_NAME, r.RES_NAME, a.TASK_NAME,
a.ASSN_ACT_WORK / 60000 AS actual_hours, a.ASSN_START_DATE AS start_date,
a.ASSN_FINISH_DATE AS finish_date, a.ASSN_WORK / 60000
AS assigned_work, a.ASSN_REM_WORK / 60000 AS remaining_work,
a.WASSN_LAST_WORK / 60000 AS assigned_last_work,
a.WASSN_SEND_UPDATE_DATE AS update_sent_date, (w.wwork_value) / 60000 AS
[work],
DateAdd(d, 7, w.WWORK_START) AS work_date,
w.wwork_start, w.wwork_finish
FROM dbo.MSP_WEB_RESOURCES r INNER JOIN
dbo.MSP_WEB_ASSIGNMENTS a ON a.WRES_ID = r.WRES_ID
INNER JOIN
dbo.MSP_WEB_PROJECTS p ON p.WPROJ_ID = a.WPROJ_ID
INNER JOIN
dbo.MSP_WEB_WORK w ON a.WASSN_ID = w.WASSN_ID
LEFT JOIN dbo.MSP_WEB_RESOURCES w1 ON a.WRES_ID_MGR = w1.WRES_ID
WHERE w.wwork_type = 1 AND w.wwork_value > 0 AND w.WWORK_START <>
w.WWORK_FINISH AND DateAdd(d, 7, w.WWORK_START) <= w.WWORK_FINISH
and r.Res_Name like @res_name
and w.wwork_start between @Begin_Date and @End_Date
End
GO
Nixm said:
I need a query that will display actual hours worked by resource for each
project and by project for each resource, totaled out by week. The date
stuff is easy and the groups etc. But I am having a fit figuring out where
the hours worked per date is stored. Is there a std query for this info?