Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,

I have result set as

SQL
Department     |achead              | location
Admin          |Telecommunication   | usa
Admin          |Telecommunication   | usa
Admin          |Computers           | uae
Admin          |Computers           | uae
Admin1         |Micro               | usa
Admin1         |Micro               | usa


i want resultset as
VB
Department        |achead             | Total_Count_Location
Admin             | null              | null
Telecommunication | null              | null
Admin             |Telecommunication  | 2
Admin             |Computers          | 2
                  |              Total| 4
Admin1            | null              | null
Micro             | null              | null
Admin1            |Micro              | 2
                  |             Total | 2


i was able to add total rows but not able to add the rows with values null.

i did something like this
SELECT      CASE GROUPING([departmant])
                  WHEN 1 THEN 'Total'
                   ELSE [departmant] END AS 'departmant',
            CASE GROUPING([achead])
                  WHEN 1 THEN 'Total'
                  ELSE [achead] END AS 'achead',
            COUNT([location])  AS 'Total_Count_Location' INTO #TMP2
FROM        temptest
GROUP BY    [departmant], [achead] WITH ROLLUP
 
SELECT  CASE achead WHEN 'Total' then '' else departmant end as departmant,
        achead,
        Total_Count_Location
FROM    #TMP2 WHERE departmant!='TOTAL'


please help
Posted
Comments
Schatak 22-Mar-14 9:12am    
Please share your table structure
ydfhskskahjj 24-Mar-14 6:26am    
Department |achead | location
Admin |Telecommunication | usa
Admin |Telecommunication | usa
Admin |Computers | uae
Admin |Computers | uae
Admin1 |Micro | usa
Admin1 |Micro | usa

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