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.
| Author |
Topic |
|
ujjaval
Posting Yak Master
108 Posts |
Posted - 2007-02-02 : 00:32:19
|
| Hello all,I am having a table say TableX with ColA, ColB, ColC, ColD.All four columns has possible values 'Yes','No','?' and null.What I want is an output for with total number of records for which each column has value 'Yes'..Something like::ColA = 89ColB = 34ColC = 23ColD = 11I want them all in as 1 query output. Is there anyway that I can get two columns output as shown above.. doesn't have to include '=' sign.. just normal two columns output like that..Thanks,Ujjaval |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-02-02 : 00:36:38
|
[code]select col = 'ColA', c = count(*)from TableXwhere ColA = 'Yes'union allselect col = 'ColB', c = count(*)from TableXwhere ColB = 'Yes'union allselect col = 'ColC', c = count(*)from TableXwhere ColC = 'Yes'union allselect col = 'ColD', c = count(*)from TableXwhere ColD = 'Yes'[/code] KH |
 |
|
|
ujjaval
Posting Yak Master
108 Posts |
Posted - 2007-02-02 : 01:12:07
|
| Thanks for that. That worked. I thought union all works with combining columns of different tables in the output.. I guess need to look more on union all..Cheers,Ujjaval |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-02-02 : 01:18:09
|
union basically is to combine multiple results set to one, not restricted by tables KH |
 |
|
|
|
|
|
|
|