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 |
|
ms
Starting Member
11 Posts |
Posted - 2008-10-17 : 06:23:07
|
| How do I do the following in a single statement.I have a field <field1> which is varchar, I want a count of all the rows which have null value in <field1> and a count of all rows when it is not null in a single statement.Thanks |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2008-10-17 : 06:34:36
|
| SELECT COUNT(*), ( SELECT COUNT(*) FROM table1 WHERE field is NULL ) FROM table1 WHERE field IS NOT NULL |
 |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2008-10-17 : 07:04:31
|
| select sum(case when field is null then 1 else 0 end) countofnull , sum(case when field is not null then 1 else 0 end) countofnotnull from table1 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-17 : 10:11:13
|
| or simply:-select count(*)-count(field) countofnull ,count(field) countofnotnull from table1 |
 |
|
|
|
|
|