Connecting Tech Pros Worldwide Help | Site Map

Converting Text to Decimal

benchpolo's Avatar
Member
 
Join Date: Sep 2007
Location: Nevada
Posts: 92
#1: Aug 4 '09
I have a set of data that has a value format of 0000014033. 0000014033 is a dollar value with 2 decimal places. I need to convert the 0000014033 to 140.33. Can someone assist me in writing the code?
Thanks.
ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,925
#2: Aug 4 '09

re: Converting Text to Decimal


What do you have so far?

--- CK
benchpolo's Avatar
Member
 
Join Date: Sep 2007
Location: Nevada
Posts: 92
#3: Aug 4 '09

re: Converting Text to Decimal


I was going to do

declare
@value varchar(9)

set @value = '0001122'

select cast(@value as decimal(5,2)) as result

but i get this error
Server: Msg 8115, Level 16, State 8, Line 6
Arithmetic overflow error converting numeric to data type numeric.
ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,925
#4: Aug 4 '09

re: Converting Text to Decimal


try

Expand|Select|Wrap|Line Numbers
  1.  
  2. declare
  3. @value varchar(9)
  4.  
  5. set @value = '0001122'
  6.  
  7. select cast(@value as decimal(10,2))/100.00 as result
  8.  
  9.  
Handle the decimal place display on your front-end. Don't stress your server. If you insist of doing it, convert the entire expression to decimal(10,2) again.


Happy Coding!!!

--- CK
benchpolo's Avatar
Member
 
Join Date: Sep 2007
Location: Nevada
Posts: 92
#5: Aug 4 '09

re: Converting Text to Decimal


Actually I'm planning to create a VIEW bec the data that comes back from our vendor has it as 0001122, and our user needs to see it in dollar with two decimal places.
Thanks for helping me. =)
Reply