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 |
|
ssmani84
Starting Member
20 Posts |
Posted - 2010-05-06 : 03:16:39
|
| hi friends ,i want to get Count of NotNull value Coloumnsmy table structure is belowColoumnName col1 col2 col3 col4 col5 col6 col7 col8 col9 col10 Value P P P P null P P null null null here i want to get Notnull value count Notmull=6 and null=4 how to get this? pls help messmaniyadav |
|
|
malpashaa
Constraint Violating Yak Guru
264 Posts |
Posted - 2010-05-06 : 04:08:12
|
| SELECT 10 - NullsCount AS NotNullCount, NullsCount FROM (SELECT CASE WHEN col1 IS NULL THEN 1 ELSE 0 END + CASE WHEN col2 IS NULL THEN 1 ELSE 0 END + ... CASE WHEN col10 IS NULL THEN 1 ELSE 0 END AS NullsCount FROM YourTable) AS T |
 |
|
|
ssmani84
Starting Member
20 Posts |
Posted - 2010-05-06 : 07:13:45
|
| Thanks malpashaa ..its working fine......ssmaniyadav |
 |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2010-05-06 : 07:42:25
|
I thought it was this you were after but reading it again I can see that the previous answer was what you were looking for. Posting it anyway:SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNSWHERE TABLE_NAME = 'MyTableName' AND IS_NULLABLE = 'YES' - LumbagoIf the facts don't fit the theory, change the facts. Albert Einstein |
 |
|
|
|
|
|