all groups > sql server odbc > march 2004 >
You're in the

sql server odbc

group:

sql convert dies on nulls


Re: sql convert dies on nulls Tenaya
3/23/2004 4:47:17 AM
sql server odbc:
Warren,

Perhaps the following will be of value to you:

create table mytable (amount varchar (10) NULL)
go

insert into mytable values ('1.0')
insert into mytable values ('')
insert into mytable values (NULL)
go

select cast(case amount when '' then '0' else amount end as decimal(25,2))
as amount from mytable

Chief Tenaya


[quoted text, click to view]

sql convert dies on nulls Waz
3/23/2004 2:00:26 PM
Hello,

I have a problem with an sql script doing a conversion

for example
select CONVERT(decimal(25,2), amount) as amount from mytable

The problem arises when there is a null or blank value for the column as
expected it bombs out.
I cant change the data in the table as it is too late for that.

Does anyone know how to somehow substitute a zero for when i come across
null or blank values and not do the conversion - within that query
i haven't much time left and my google searches have returned nothing of
interest yet although i will keep trying

Thanks very much in advance for any help

Warren




Re: sql convert dies on nulls Waz
3/24/2004 8:58:36 AM
Hi Chief

Thankyou very much for your help. i spent hours trying to work out a
solution


Best Regards
Waz




[quoted text, click to view]

sql convert dies on nulls Tabatha
3/24/2004 12:15:36 PM
Try this:

select CONVERT(decimal(25,2), isnull(amount,0) ) as amount
from mytable

[quoted text, click to view]
AddThis Social Bookmark Button