Question : Percent Of Miles

OK this is probably easy, but I can't figure it out. I have a table with order number and trip miles trip miles and I' trying to get the percentage of the miles of the trip part to all the miles of the trip. If it's 100 percent I get 1, else I get 0.

(No column name)      OrderNum      ResType      Resource      Terminal      Division      TotalMiles      LegMiles      PctMiles      MaintCost      OfficeCost      DispCost
1      93567      Tractor      2711      OMA      CHEM      709      709      1.0000      NULL      NULL      NULL
0      93760      Tractor      BT03      OMA      HERB      1774      1498      0.0000      NULL      NULL      NULL
0      93760      Tractor      2541      OMA      HERB      1774      276      0.0000      NULL      NULL      NULL

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
insert into cost (Ordernum, ResType, Resource, Terminal, Division,
	TotalMiles, LegMiles)
select distinct OrderNum, 
	case
	when lgh_tractor <> 'UNKNOWN' then 'Tractor'
	when lgh_carrier is not null then 'Carrier'
	end,
	case
	when lgh_tractor <> 'UNKNOWN' then lgh_tractor
	when lgh_carrier is not null then lgh_carrier
	end,
	lgh_class1,
	lgh_class2, 
	(select sum(lgh_miles) from legheader l2 where l2.ord_hdrnumber = OrderNum),
	(select sum(lgh_miles) from legheader l3 where l3.ord_hdrnumber = OrderNum 
		and l3.lgh_tractor = l.lgh_tractor)
from revenue w left join legheader l on w.OrderNum = l.ord_hdrnumber

select LegMiles/TotalMiles, * from cost

Answer : Percent Of Miles

select 1.0 * LegMiles/TotalMiles, * from cost
Random Solutions  
 
programming4us programming4us