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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Implied decimal places

Status
Not open for further replies.

mwa

Programmer
Jul 12, 2002
507
US
I have a table that contains a field called transaction_amt. It is defined as a varchar(13). The data in this field is right justified and numeric with an implied decimal place of 2.
Example:
transaction_amt
12345
234567

These entries should be 123.45 and 2345.67. I'm taking these values and inserting them into a field in another table that is defined as money. Is there a function that can be used to convert these over to the correct decimal places? Or should I just use the substring function and slam a . in there?

mwa
<><
 
SELECT CAST(transaction_amt AS MONEY)

or

SELECT CONVERT(MONEY, transaction_amt)


Refer to the Books OnLine for CAST and CONVERT

-SQLBill
 
SQLBILL:

Your solution doesn't deal with the implied decimal palce.

mwa:
Try this:

SELECT (CONVERT(money, '12345'))/100

~Brian
 
Oh right... Use a little 4th grade math... Why didn't I think of that? Must be time for some more Mt. Dew...

Thanks bdreed35...

mwa
<><
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top