Link to home
Start Free TrialLog in
Avatar of ckangas7
ckangas7

asked on

Converting varchar hours and minutes to 2 place decimal

I have raw data being imported into a table as varchar and need to convert it into numeric 2 place decimal format.  The data comming represents time in terms of hour and minutes.  Data looks like this:

0000000
0015000
0030000  
0730000

When converted it should look like:

0.00
0.25
0.50
7.50

I tried:
Insert into  t_employee_detail
(emp_time)
select CAST(f7 as numeric(8, 2))
from t_insert_emp_detail

But that didn't do it.  How do I do this?
SOLUTION
Avatar of TextReport
TextReport
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
try this

SELECT CAST(f7 AS DECIMAL(8,2))
Sorry about the proposed solution, I normally only post as comments must have clicked on Proposed by accident.
Cheers, Andrew
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Anthony Perkins
Or for an all numeric calculation:
Insert      t_employee_detail(emp_time)
Select      CAST((CAST(f7 as int) / 100000) +
      ((CAST(f7 as int) / 1000) % 100) / 100.0 as numeric(8,2))
From      t_insert_emp_detail
Avatar of ckangas7
ckangas7

ASKER

Hi,

Great input guys.  One thing.  After I insert the data it is automatically being rounded up to the nearest whole number instead of displaying in the 2 place decimal format that I need.  The column type shows as [emp_time] [decimal](10, 0) NULL .  I tried to change it to change it with:

ALTER table t_employee_detail
modify emp_time decimal (8,2)

but am getting a syntax error.  What am I doing wrong?
Try

ALTER table t_employee_detail
ALTER COLUMN emp_time decimal (8,2)
Thanks much all who commented.