Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting varchar to decimal 1

Status
Not open for further replies.

Naith

Programmer
May 14, 2002
2,530
GB
Hi,

I have currency values like "$ 45,001.45" etc stored as varchar. Because I need to do calculations on these fields, I've tried to convert this column to decimal:
Code:
convert(decimal(18,2),replace("bill_amt$",',',''))
However, there are a lot of records with null or '' values which I guess are interfering with this conversion, as I'm returning an "unable to convert" error.

Any suggestions how I might achieve this?

Naith
 
Oh, and I've already stripped the "$ " section of the string out. Forgot to mention that in the original post.
 
select convert(money, '$ 45,001.45')

... and then convert that to decimal if needed.

------
Theory: everybody knows everything, nothing works
Practice: everything works, nobody knows why

[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top