SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 replace Null value to string
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

nrsh_ram
Starting Member

Malaysia
3 Posts

Posted - 06/15/2010 :  05:40:05  Show Profile  Reply with Quote
hi to all...

i need help..
i have a set of data where its retrieve a data & null...
the column is datetime

for null value i want to replace it with '-' char

i try like this
SELECT REPLACE(NULL,NULL,'-')

output..still appear NULL...
coz inside there its nothing to have to replace...

what should i do for output '-'?

webfred
Flowing Fount of Yak Knowledge

Germany
8760 Posts

Posted - 06/15/2010 :  05:46:41  Show Profile  Visit webfred's Homepage  Reply with Quote
select isnull(Columnname,'-')


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

khtan
In (Som, Ni, Yak)

Singapore
17584 Posts

Posted - 06/15/2010 :  05:49:39  Show Profile  Reply with Quote
you should be using ISNULL() to do that. REPLACE does not work for NULL value.

Anyway, what you wanted is just a presentation issue. You should be handling that in your front end application where the data is being displayed.

If you really want to do it in the T-SQL side, then you should also convert the datetime to a string


select isnull(convert(varchar(10), datecol, 121), '-')
from   yourtable




KH
Time is always against us

Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22744 Posts

Posted - 06/15/2010 :  06:20:46  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
You can't have both valid dates as well as - for NULL values

Madhivanan

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

nrsh_ram
Starting Member

Malaysia
3 Posts

Posted - 06/15/2010 :  20:20:27  Show Profile  Reply with Quote
quote:
Originally posted by madhivanan

You can't have both valid dates as well as - for NULL values

Madhivanan

Failing to plan is Planning to fail



ok Madhivanan,

can u advice me the correct way to get the exact output...
i want change the null to string...the changes that not for overall column bcoz it will change the format of datetime to string..

plz help me..
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17584 Posts

Posted - 06/15/2010 :  20:35:26  Show Profile  Reply with Quote
quote:
Originally posted by nrsh_ram

quote:
Originally posted by madhivanan

You can't have both valid dates as well as - for NULL values

Madhivanan

Failing to plan is Planning to fail



ok Madhivanan,

can u advice me the correct way to get the exact output...
i want change the null to string...the changes that not for overall column bcoz it will change the format of datetime to string..

plz help me..



Do it in your front end application


KH
Time is always against us

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000