Using below queries we can find the sum of any value for parent level hierarchy and child level hierarchies:
=========================================================================
DECLARE @STARTDATE DATETIME
DECLARE @TODATE DATETIME
SET @STARTDATE = '1/1/2011'
SET @TODATE = '1/31/2011'
SELECT CASE WHEN (GROUPING(PP.ProjectName)= 1) THEN 'Overall Total'
ELSE PP.ProjectName END AS Projects
,CASE WHEN (GROUPING(UU.Firstname) = 1) Then 'Project Total'
ELSE UU.Firstname END AS Employee
,SUM(ISNULL(Duration,0)) AS BookedHrs
FROM [Dotnet2005].[Timesheet].dbo.Timetrack TT
JOIN [Dotnet2005].[Timesheet].dbo.Projects PP ON PP.ProjectId = TT.ProjectID
JOIN [Dotnet2005].[Timesheet].dbo.[User] UU ON UU.UserID = TT.UserID
WHERE TT.Datee >= @STARTDATE AND TT.Datee <= @TODATE
GROUP BY PP.ProjectName
,UU.Firstname WITH ROLLUP
ORDER BY PP.Projectname
DECLARE @STARTDATE DATETIME
DECLARE @TODATE DATETIME
SET @STARTDATE = '1/1/2011'
SET @TODATE = '1/31/2011'
SELECT CASE WHEN (GROUPING(DD.DepartmentName) = 1) THEN 'ALL'
ELSE DD.DepartmentName END AS 'Department'
,CASE WHEN (GROUPING(CA.CostTypeName) = 1) THEN 'Department Total'
ELSE CA.CostTypeName END AS 'Cost Type Total'
,SUM(ISNULL(Duration,0)) AS BookedHrs
FROM [Dotnet2005].[Timesheet].dbo.Timetrack TT
JOIN [Dotnet2005].[Timesheet].dbo.[User] UU ON UU.UserID = TT.UserID
JOIN [Dotnet2005].[Timesheet].dbo.[Department] DD ON DD.DepartmentID = UU.DepartmentID
JOIN [Dotnet2005].[Timesheet].dbo.[Tasks] TA ON TA.Taskid = TT.Taskid
JOIN [Dotnet2005].[Timesheet].dbo.[CostType] CA ON CA.CostTypeid = TA.CostTypeid
WHERE TT.Datee >= @STARTDATE AND TT.Datee <= @TODATE
GROUP BY DD.DepartmentName
,CA.CostTypeName WITH ROLLUP
ORDER BY DD.DepartmentName
,CA.CostTypeName