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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 replace Null value to string

Author  Topic 

nrsh_ram
Starting Member

3 Posts

Posted - 2010-06-15 : 05:40:05
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
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-06-15 : 05:46:41
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)

17689 Posts

Posted - 2010-06-15 : 05:49:39
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
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-06-15 : 06:20:46
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

3 Posts

Posted - 2010-06-15 : 20:20:27
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)

17689 Posts

Posted - 2010-06-15 : 20:35:26
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
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -