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 |
|
kkiranvr
Yak Posting Veteran
54 Posts |
Posted - 2009-04-22 : 19:32:02
|
| Hi all, My input table is having 4 recordsCol1 Col2 Col3 Col4 215 220 225 226210 null null null213 223 null null430 423 524 nullNow i want o/p as count of col1, col2, col3 and col4 in Col5 like shown in belowCol1 Col2 Col3 Col4 Col5215 220 225 226 4210 null null null 1213 223 null null 2430 423 524 null 3Can any one help me in this.-Thanks N Regards,Chinna. |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-04-22 : 20:49:06
|
| [code]Select col1,col2,col3,Count(col1)+Count(col2)+Count(col3)from tableGroup by col1,col2,col3[/code] |
 |
|
|
notmyrealname
98 Posts |
Posted - 2009-04-22 : 21:27:29
|
| SELECT Col1, Col2, Col3, Col4, ISNULL(Col1 / Col1, 0) + ISNULL(Col2 / Col2, 0) + ISNULL(Col3 / Col3, 0) + ISNULL(Col4 / Col4, 0) AS Col5FROM Table |
 |
|
|
maeenul
Starting Member
20 Posts |
Posted - 2009-04-23 : 12:57:19
|
| jswota is right. The way you want to count is not the sql count. SQL count() works for rows, but you want to count non null column values.-----------------------maeenulhttp://www.programmingsolution.nethttp://sqlservertipsntricks.blogspot.com |
 |
|
|
|
|
|
|
|