Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

converting integer field into money

Posted on 2008-10-06
5
Medium Priority
?
326 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 1000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

927 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