Solved

converting integer field into money

Posted on 2008-10-06
5
317 Views
Last Modified: 2012-05-05
I'm converting a data file that has a fee field with no decimals. I need to cast this field as money but I'm stuck on how to proceed with this.

Ex:

data field = 25557
want to to convert it to show 255.57
0
Comment
Question by:jorbroni
  • 3
  • 2
5 Comments
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22654416
select cast(datafield as numeric(10,2)/100
from YourTable
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22654420
or perhaps this, depending upon your db engine:


select convert(numeric(10,2), yourDataField)/100
from YourTable
0
 
LVL 1

Author Comment

by:jorbroni
ID: 22654464

I get the following error

Arithmetic overflow error converting varchar to data type numeric.
0
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 250 total points
ID: 22654484
Well 10,2 was just a starting point.  If you have greater than 8 digits to the left (>99 million) then you need to expand your data type beyond 10,2.
0
 
LVL 1

Author Comment

by:jorbroni
ID: 22654491

Nevermind,

I figured out what I did wrong with your script.

Thanks for your help sir.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now