Shortcuts

Issue in SQL Group by Query

Actually, I want to have a subtotal by grouping the First names, but displaying the Project name, project id and alternative proj_name of a employee..which will change.

Hi, I am trying to write a Store Proc to generate a report. But, the below query gives me 4 rows of each item. I want subtotal of all the months grouped by persons first name, but at the same time, I want to display the Project name, project id and alternative proj_name of all the individual projects as well. I am getting 4 rows in which the same output is repeated, with nulls in other three firleds (Project name, project id and alternative proj_name ). This is not my intended output.... please help!

Re: Issue in SQL Group by Query

SELECT
isnull(convert(VARCHAR, [project]), 'tot') AS [project],
isnull(convert(VARCHAR, [name]), 'sub tot) AS [name],
max([project_id]) as [project_id]
sum(days) as Days
FROM table A
GROUP BY [project], [name] with rollup
ORDER BY [project] ;