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 |
sg2255551
Constraint Violating Yak Guru
274 Posts |
Posted - 2014-03-09 : 09:47:14
|
hiHow do I count numbers of columns that has value?For exampleColA ColB ColC ColD ColE ColF12 10.5 50 32 NULL NULLIn this example, I should have a count of 4How should go about doing it?many thanks. |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2014-03-09 : 09:50:32
|
[code]CASE WHEN ColA IS NOT NULL THEN 1 ELSE 0 END+ CASE WHEN ColB IS NOT NULL THEN 1 ELSE 0 END+ CASE WHEN ColC IS NOT NULL THEN 1 ELSE 0 END+ CASE WHEN ColD IS NOT NULL THEN 1 ELSE 0 END+ . . .[/code] KH[spoiler]Time is always against us[/spoiler] |
|
|
sg2255551
Constraint Violating Yak Guru
274 Posts |
Posted - 2014-03-09 : 10:05:56
|
hiMy apology, but how do I add up all the 1? Many thanks |
|
|
sg2255551
Constraint Violating Yak Guru
274 Posts |
Posted - 2014-03-09 : 10:06:49
|
sorry I didn't see the + sign. I thought it is a concat. ThanksI got it now. Thanks |
|
|
|
|
|