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
 Setting Null to "N/A"

Author  Topic 

yccyccycc
Starting Member

4 Posts

Posted - 2009-07-08 : 14:07:55
does anyone know how to set null data to "N/A"?

I am a newbie and still learning. Thanks!!!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-07-08 : 14:09:54
ISNULL(yourfield,'N/A') or COALESCE(Yourfield,'N/A')

your field should be of character type for doing this
Go to Top of Page

yccyccycc
Starting Member

4 Posts

Posted - 2009-07-08 : 14:30:10
Thanks.

how about if the origional datatype is numeric?

To illustrate, I have a set of data which is numeric after all of the mathematic calculation. Some of the data are shown empty. I would like to fill out this empty spaces with "N/A"

thank you!
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2009-07-08 : 14:32:40
That is a dispaly issue and should be handled in your front end application.

However, if you insist you can still use COALESCE:
SELECT COALESCE(CAST(NumVal AS VARCHR(38)), 'N/A') FROM My Table 
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-07-08 : 15:49:27
You should leave it as null

Although, most people would prefer space or empty string for char data and 0 for numeric

Col1 varchar(10) null DEFAULT('')
, Col2 int null DEFAULT(0)



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -