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
 How to Replace a null value

Author  Topic 

pgmr1998
Yak Posting Veteran

66 Posts

Posted - 2008-02-06 : 17:39:17
how can I insert a constant value such as the word "NoPhone" when a field value from a select statement is null?
Here is my code:

select AgencyName
,AgencyLoc,
,ISNULL(AgencyPhone.Agency,) as phone

How can we put in the words "nophone" when phone is null?

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-02-06 : 17:41:02
you just about had it. Did you look at the function Books Online

,ISNULL(AgencyPhone.Agency, 'nophone') as phone

Be One with the Optimizer
TG
Go to Top of Page

pgmr1998
Yak Posting Veteran

66 Posts

Posted - 2008-02-06 : 17:44:17
Thanks...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-06 : 22:56:56
Make sure your Agency field has a length of atleast 7 as ISNULL() always returns datatype of first argument. Else its better to use COALESCE here.
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2008-02-07 : 00:17:02
COALESCE(COLNAME,'NOPHONE')
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-07 : 07:45:06
quote:
Originally posted by visakh16

Make sure your Agency field has a length of atleast 7 as ISNULL() always returns datatype of first argument. Else its better to use COALESCE here.


Also refer http://sqlblogcasts.com/blogs/madhivanan/archive/2007/10/04/isnull-or-coalesce.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -