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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Adding only Not null columns

Author  Topic 

akpbond007
Starting Member

5 Posts

Posted - 2010-06-16 : 02:50:42
Hi
I have three columns h1 h2 and h3. i want to h1+h2+h3. if any of the colunn in NULL omit it.

Please can any one help me

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-06-16 : 02:58:57
Are we talking about numeric addition?
isnull(h1,0)+isnull(h2,0)+isnull(h3,0)

Or are we talking about concatenating char values?
isnull(h1,'')+isnull(h2,'')+isnull(h3,'')

Or we are talking about concatenating numeric values?
isnull(convert(varchar(255),h1),'')+isnull(convert(varchar(255),h2),'')+isnull(convert(varchar(255),h3),'')



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

akpbond007
Starting Member

5 Posts

Posted - 2010-06-16 : 03:00:15
Hi

Also i have three columns h1 h2 and h3. I need to get the count of not null columns. If h1 and 2 is not null and h3 is NLL. The result should be 2
Go to Top of Page

nirene
Yak Posting Veteran

98 Posts

Posted - 2010-06-16 : 03:02:44
Select Case When H1 Is null Then 0 Else 1 End +
Case When H2 Is null Then 0 Else 1 End +
Case When H3 Is null Then 0 Else 1 End from <Table>

Nirene
Go to Top of Page

akpbond007
Starting Member

5 Posts

Posted - 2010-06-16 : 03:50:13
Thanks..

The query worked properly
Go to Top of Page
   

- Advertisement -