blah blah blah is here! blah blah » Close

up0down
link

hi! i have a query like this:
SELECT Cast(Replace(room_rate2, 'US$','') as decimal) as maxRate
FROM tblrates
now why is it i received an error like this:
Error converting data type varchar to numeric.

last answered 2 years ago

1 answers

up0down
link

It seems to be complaining that room_rate2, after removing the string 'US$', cannot be parsed to a decimal, which is odd when you were using a regex to validate it in your earlier thread.
I'd try using a string literal instead to make sure the code is working as expected:
SELECT Cast(Replace('US$ 100.89', 'US$','') as decimal) as maxRate FROM tblrates
If it is, then you need to find some way of displaying room_rate2 to see what's actually in there.

up0down
link

thanks vulpes, you gave me an idea. i have converted it to money instead of decimal. in that way it is possible to cast it.

This post was imported from csharpfriends, if you have a similiar question please ask it again.

All previous members have been migrated, hope you enjoy the new platform!

Feedback