Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want o get total in the footer for this query
SQL
SELECT 'Total' AS Total, SUM([Coding]), SUM([Unit Testing]),
       SUM([User Manual]), SUM([Meetings]), SUM([Testing])
FROM (SELECT TOP (100)
      Name,
      [Coding],[Unit Testing],[User Manual],[Meetings],[Testing],
      TaskDate,
      COALESCE([Coding],0) + COALESCE([Unit Testing],0) +
               COALESCE([User Manual],0) + COALESCE([Meetings],0) +
               COALESCE([Testing],0) AS Total
      FROM (SELECT
            TaskTitle As Title,
            Hours,
            Employee_Name AS Name,        
            TaskDate
            FROM TimeSheet TS,
                 employee E,
                 Timesheetdetails TSD,
                 Task T
            WHERE
                TS.EmployeeID = E.Employee_EmpID AND
                TSD.TaskID = T.TaskID AND
                TS.TImeSheetID = TSD.TimeSheetID AND
                T.Status='A' AND
                TS.ProjectID = 43 AND
                TSD.TaskDate >='09/26/2011' AND
                TSD.TaskDate<='10/02/2011'
            ) up
      PIVOT (SUM(Hours) FOR Title IN ([Coding], [Unit Testing], 
                                      [User Manual],
                                      [Meetings],[Testing])) AS pvt           
      ORDER BY TaskDate DESC)          
      GROUP BY SUM([Coding]), SUM([Unit Testing]), SUM([User Manual]),
                   SUM([Meetings]), SUM([Testing])



but its showing error
Posted
Updated 2-Oct-11 22:33pm
v3
Comments
Bala Selvanayagam 3-Oct-11 4:43am    
Can you please post the table structure for us to try your query please ?
Inderjeet Kaur 3-Oct-11 7:15am    
I have rectified the query and the error is
"Incorrect syntax near the keyword 'GROUP'."



SELECT 'Total' AS Total, SUM([Coding]), SUM([Unit Testing]),
SUM([User Manual]), SUM([Meetings]), SUM([Testing])
FROM (SELECT
Name,
[Coding],[Unit Testing],[User Manual],[Meetings],[Testing],
TaskDate,
COALESCE([Coding],0) + COALESCE([Unit Testing],0) +
COALESCE([User Manual],0) + COALESCE([Meetings],0) +
COALESCE([Testing],0) AS Total
FROM (SELECT
TaskTitle As Title,
Hours,
Employee_Name AS Name,
TaskDate
FROM TimeSheet TS,
employee E,
Timesheetdetails TSD,
Task T
WHERE
TS.EmployeeID = E.Employee_EmpID AND
TSD.TaskID = T.TaskID AND
TS.TImeSheetID = TSD.TimeSheetID AND
T.Status='A' AND
TS.ProjectID = 43 AND
TSD.TaskDate >='09/26/2011' AND
TSD.TaskDate<='10/02/2011'
) up
PIVOT (SUM(Hours) FOR Title IN ([Coding], [Unit Testing],
[User Manual],
[Meetings],[Testing])) AS pvt
)
GROUP BY SUM([Coding]), SUM([Unit Testing]), SUM([User Manual]),
SUM([Meetings]), SUM([Testing])

1 solution

At first sight the open parenthesis in FROM (SELECT TOP (100) doesn't seem to be matched by a closing parenthesis.
That might just be mistake you made when copying the sql, but as you do not tell us what error message you're actually getting, that's my guess.

What I'm trying to say, don't tell us "this doesn't work", "it shows an error" and the like, you might as well just not mention it as it doesn't really help anyone who tries to help you resolve your issue. Tell us I get "this error message <the error="" message="">".
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900