Technical Article

Calculate Velocity - Most Advanced UOC

,

This function is used to calculate the actual unit of conversion for velocity/speed.

This is a most advanced generic function , which suppose to return values for 42 combinations.

Regards,

Vignesh Arulmani

create function fn_calc_uoc_velocity(@FromConversionUnit varchar(64),@ToConversionUnit varchar(64),@UnitValue float)
returns float
as
begin

--VELOCITY
/*===============ACRONYM==========
cmps  - centimeter per second
fps   - feet per second
kmph  - kilometer per hour
mtps  - meter per second
mph   - miles per hour

*/
declare @returnvalue float

select @returnvalue = 
case 
when @FromConversionUnit = 'cmps' and @ToConversionUnit = 'fps' then @UnitValue * 0.0328083989501312
when @FromConversionUnit = 'cmps' and @ToConversionUnit = 'kmph' then @UnitValue * 0.036
when @FromConversionUnit = 'cmps' and @ToConversionUnit = 'knots' then @UnitValue * 0.019438444924406
when @FromConversionUnit = 'cmps' and @ToConversionUnit = 'mach' then @UnitValue * 2.938641460175678e-5
when @FromConversionUnit = 'cmps' and @ToConversionUnit = 'mtps' then @UnitValue * 0.01
when @FromConversionUnit = 'cmps' and @ToConversionUnit = 'mph' then @UnitValue * 0.022369362920544

when @FromConversionUnit = 'fps' and @ToConversionUnit = 'cmps' then @UnitValue * 30.48
when @FromConversionUnit = 'fps' and @ToConversionUnit = 'kmph' then @UnitValue * 1.09728
when @FromConversionUnit = 'fps' and @ToConversionUnit = 'knots' then @UnitValue * 0.5924838012958963
when @FromConversionUnit = 'fps' and @ToConversionUnit = 'mach' then @UnitValue * 8.956979170615466e-4
when @FromConversionUnit = 'fps' and @ToConversionUnit = 'mtps' then @UnitValue * 0.3048
when @FromConversionUnit = 'fps' and @ToConversionUnit = 'mph' then @UnitValue * 0.6818181818181818

when @FromConversionUnit = 'kmph' and @ToConversionUnit = 'cmps' then @UnitValue * 27.77777777777778
when @FromConversionUnit = 'kmph' and @ToConversionUnit = 'fps' then @UnitValue * 0.9113444152814232
when @FromConversionUnit = 'kmph' and @ToConversionUnit = 'knots' then @UnitValue * 0.5399568034557235
when @FromConversionUnit = 'kmph' and @ToConversionUnit = 'mach' then @UnitValue * 8.162892944932439e-4
when @FromConversionUnit = 'kmph' and @ToConversionUnit = 'mtps' then @UnitValue * 0.2777777777777778
when @FromConversionUnit = 'kmph' and @ToConversionUnit = 'mph' then @UnitValue * 0.621371192237334

when @FromConversionUnit = 'knots' and @ToConversionUnit = 'cmps' then @UnitValue * 51.44444444444444
when @FromConversionUnit = 'knots' and @ToConversionUnit = 'fps' then @UnitValue * 1.687809857101196
when @FromConversionUnit = 'knots' and @ToConversionUnit = 'kmph' then @UnitValue * 1.852
when @FromConversionUnit = 'knots' and @ToConversionUnit = 'mach' then @UnitValue * 0.0015117677734015
when @FromConversionUnit = 'knots' and @ToConversionUnit = 'mtps' then @UnitValue * 0.5144444444444444
when @FromConversionUnit = 'knots' and @ToConversionUnit = 'mph' then @UnitValue * 1.150779448023543

when @FromConversionUnit = 'mach' and @ToConversionUnit = 'cmps' then @UnitValue * 34029.33
when @FromConversionUnit = 'mach' and @ToConversionUnit = 'fps' then @UnitValue * 1116.447834645669
when @FromConversionUnit = 'mach' and @ToConversionUnit = 'kmph' then @UnitValue * 1225.05588
when @FromConversionUnit = 'mach' and @ToConversionUnit = 'knots' then @UnitValue * 661.4772570194384
when @FromConversionUnit = 'mach' and @ToConversionUnit = 'mtps' then @UnitValue * 340.2933
when @FromConversionUnit = 'mach' and @ToConversionUnit = 'mph' then @UnitValue * 761.2144327129563

when @FromConversionUnit = 'mtps' and @ToConversionUnit = 'cmps' then @UnitValue * 100.0
when @FromConversionUnit = 'mtps' and @ToConversionUnit = 'fps' then @UnitValue * 3.280839895013123
when @FromConversionUnit = 'mtps' and @ToConversionUnit = 'kmph' then @UnitValue * 3.6
when @FromConversionUnit = 'mtps' and @ToConversionUnit = 'knots' then @UnitValue * 1.943844492440605
when @FromConversionUnit = 'mtps' and @ToConversionUnit = 'mach' then @UnitValue * 0.0029386414601757
when @FromConversionUnit = 'mtps' and @ToConversionUnit = 'mph' then @UnitValue * 2.236936292054402

when @FromConversionUnit = 'mph' and @ToConversionUnit = 'cmps' then @UnitValue * 44.704
when @FromConversionUnit = 'mph' and @ToConversionUnit = 'fps' then @UnitValue * 1.466666666666667
when @FromConversionUnit = 'mph' and @ToConversionUnit = 'kmph' then @UnitValue * 1.609344
when @FromConversionUnit = 'mph' and @ToConversionUnit = 'knots' then @UnitValue * 0.8689762419006479
when @FromConversionUnit = 'mph' and @ToConversionUnit = 'mach' then @UnitValue * 0.0013136902783569
when @FromConversionUnit = 'mph' and @ToConversionUnit = 'mtps' then @UnitValue * 0.44704

when @FromConversionUnit = @ToConversionUnit then @UnitValue * 1.0
end

return(@returnvalue)

end
go



--examples
select dbo.fn_calc_uoc_velocity('cmps','fps' ,10)
select dbo.fn_calc_uoc_velocity('cmps','kmph',10)
select dbo.fn_calc_uoc_velocity('cmps','knots',10)
select dbo.fn_calc_uoc_velocity('cmps','mach',10)
select dbo.fn_calc_uoc_velocity('cmps','mtps',10)
select dbo.fn_calc_uoc_velocity('cmps','mph',10)

select dbo.fn_calc_uoc_velocity('fps','cmps' ,10)
select dbo.fn_calc_uoc_velocity('fps','kmph',10)
select dbo.fn_calc_uoc_velocity('fps','knots',10)
select dbo.fn_calc_uoc_velocity('fps','mach',10)
select dbo.fn_calc_uoc_velocity('fps','mtps',10)
select dbo.fn_calc_uoc_velocity('fps','mph',10)

select dbo.fn_calc_uoc_velocity('kmph','cmps' ,10)
select dbo.fn_calc_uoc_velocity('kmph','fps',10)
select dbo.fn_calc_uoc_velocity('kmph','knots',10)
select dbo.fn_calc_uoc_velocity('kmph','mach',10)
select dbo.fn_calc_uoc_velocity('kmph','mtps',10)
select dbo.fn_calc_uoc_velocity('kmph','mph',10)

select dbo.fn_calc_uoc_velocity('knots','cmps' ,10)
select dbo.fn_calc_uoc_velocity('knots','fps',10)
select dbo.fn_calc_uoc_velocity('knots','kmph',10)
select dbo.fn_calc_uoc_velocity('knots','mach',10)
select dbo.fn_calc_uoc_velocity('knots','mtps',10)
select dbo.fn_calc_uoc_velocity('knots','mph',10)

select dbo.fn_calc_uoc_velocity('mach','cmps' ,10)
select dbo.fn_calc_uoc_velocity('mach','fps',10)
select dbo.fn_calc_uoc_velocity('mach','kmph',10)
select dbo.fn_calc_uoc_velocity('mach','knots',10)
select dbo.fn_calc_uoc_velocity('mach','mtps',10)
select dbo.fn_calc_uoc_velocity('mach','mph',10)

select dbo.fn_calc_uoc_velocity('mtps','cmps' ,10)
select dbo.fn_calc_uoc_velocity('mtps','fps',10)
select dbo.fn_calc_uoc_velocity('mtps','kmph',10)
select dbo.fn_calc_uoc_velocity('mtps','knots',10)
select dbo.fn_calc_uoc_velocity('mtps','mach',10)
select dbo.fn_calc_uoc_velocity('mtps','mph',10)

select dbo.fn_calc_uoc_velocity('mph','cmps' ,10)
select dbo.fn_calc_uoc_velocity('mph','fps',10)
select dbo.fn_calc_uoc_velocity('mph','kmph',10)
select dbo.fn_calc_uoc_velocity('mph','knots',10)
select dbo.fn_calc_uoc_velocity('mph','mach',10)
select dbo.fn_calc_uoc_velocity('mph','mtps',10)

Rate

1 (4)

You rated this post out of 5. Change rating

Share

Share

Rate

1 (4)

You rated this post out of 5. Change rating