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)
 convert from nchar to money

Author  Topic 

rookie_sql
Constraint Violating Yak Guru

443 Posts

Posted - 2008-05-01 : 06:59:27
Hi i've a staging table were i have datatypes of nchar.
I'd like to convert these to money datatype

Am trying to do this like this but the data return is not correct there is aslo null and blank rows so i must account for them also.

select cast(IsNumeric((Value2)) as money)
from tbl_Sales

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2008-05-01 : 07:44:04
quote:
the data return is not correct
What's wrong with it?

Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-01 : 07:45:31
select case when IsNumeric(Value2) =1 then cast(Value2) as money else 0 end
from tbl_Sales

however you should be careful using IsNumeric function

http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/enhanced-isnumeric-function.aspx
Go to Top of Page

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2008-05-01 : 07:48:01
IsNumeric is pretty useless. Here's an alternative function which should help you, I think...
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=90279

Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2008-05-01 : 07:48:56
quote:
Originally posted by visakh16

select case when IsNumeric(Value2) =1 then cast(Value2) as money else 0 end
from tbl_Sales

however you should be careful using IsNumeric function

http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/enhanced-isnumeric-function.aspx


Or that one

Ryan Randall
Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page

ganeshkumar08
Posting Yak Master

187 Posts

Posted - 2008-05-02 : 04:53:56
Hello

select case when IsNumeric('3.5') =1 then cast('3.5' as money) else 0 end

Try this
Ganesh
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-02 : 04:56:19
quote:
Originally posted by ganeshkumar08

Hello

select case when IsNumeric('3.5') =1 then cast('3.5' as money) else 0 end

Try this
Ganesh


Have you reffered the links which i & Ryan posted on ISNUMERIC?
Go to Top of Page

ganeshkumar08
Posting Yak Master

187 Posts

Posted - 2008-05-02 : 05:13:16
Yes, now only i reffered, now i got it
Go to Top of Page
   

- Advertisement -