Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Formate sql table

Author  Topic 

advaghela
Starting Member

1 Post

Posted - 2014-09-02 : 01:34:18
select
sum(case flag when 1 then 1 else 0) as active,
sum(case flag when 2 then 1 else 0) as closed
from table

output

------------
active|close
------------
29| 30
------------

i need this output like this ..

-----------------
total_active | 29
-----------------
total_closed | 30
-----------------

please help me...
thanks in advance..

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-09-02 : 03:17:18
[code]
select 'total active' , count(*) from table where flag = 1
union all
select 'total closed' , count(*) from table where flag = 2
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2014-09-02 : 07:44:34
or

select case flag when 1 then 'total active' when 2 then 'total closed' end as flag, count(*) as total from table
group by case flag when 1 then 'total active' when 2 then 'total closed' end



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -