Technical Article

Calculate Energy - Most Advanced UOC

,

This function is used to calculate the actual unit of conversion for energy.

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

Regards,

Vignesh Arulmani

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

--ENERGY
/*===============ACRONYM==========
BTU - British Thermal Unit
C   - Calorie
EV  - Electron Volts
FP  - Foot Pound
J   - Joule
KC  - KiloCalorie
KJ  - KiloJoule

*/
declare @returnvalue float

select @returnvalue = 
case 
when @FromConversionUnit = 'BTU' and @ToConversionUnit = 'C' then @UnitValue * 251.9957963122194
when @FromConversionUnit = 'BTU' and @ToConversionUnit = 'EV' then @UnitValue * 6585142025517001000000.0
when @FromConversionUnit = 'BTU' and @ToConversionUnit = 'FP' then @UnitValue * 778.1693709678747
when @FromConversionUnit = 'BTU' and @ToConversionUnit = 'J' then @UnitValue * 1055.056
when @FromConversionUnit = 'BTU' and @ToConversionUnit = 'KC' then @UnitValue * 0.2519957963122194
when @FromConversionUnit = 'BTU' and @ToConversionUnit = 'KJ' then @UnitValue * 1.055056

when @FromConversionUnit = 'C' and @ToConversionUnit = 'BTU' then @UnitValue * 0.003968320164996
when @FromConversionUnit = 'C' and @ToConversionUnit = 'EV' then @UnitValue * 26131951889221600000
when @FromConversionUnit = 'C' and @ToConversionUnit = 'FP' then @UnitValue * 3.088025206594056
when @FromConversionUnit = 'C' and @ToConversionUnit = 'J' then @UnitValue * 4.1868
when @FromConversionUnit = 'C' and @ToConversionUnit = 'KC' then @UnitValue * 0.001
when @FromConversionUnit = 'C' and @ToConversionUnit = 'KJ' then @UnitValue * 0.0041868

when @FromConversionUnit = 'EV' and @ToConversionUnit = 'BTU' then @UnitValue * 1.518570132770204e-22 
when @FromConversionUnit = 'EV' and @ToConversionUnit = 'C' then @UnitValue * 3.826732898633801e-20
when @FromConversionUnit = 'EV' and @ToConversionUnit = 'FP' then @UnitValue * 1.181704764988391e-19
when @FromConversionUnit = 'EV' and @ToConversionUnit = 'J' then @UnitValue * 1.60217653e-19
when @FromConversionUnit = 'EV' and @ToConversionUnit = 'KC' then @UnitValue * 3.826732898633801e-23
when @FromConversionUnit = 'EV' and @ToConversionUnit = 'KJ' then @UnitValue * 1.60217653e-22

when @FromConversionUnit = 'FP' and @ToConversionUnit = 'BTU' then @UnitValue * 0.0012850672839464 
when @FromConversionUnit = 'FP' and @ToConversionUnit = 'C' then @UnitValue * 0.3238315535328652
when @FromConversionUnit = 'FP' and @ToConversionUnit = 'EV' then @UnitValue * 8.462350577132721e+18
when @FromConversionUnit = 'FP' and @ToConversionUnit = 'J' then @UnitValue * 1.3558179483314
when @FromConversionUnit = 'FP' and @ToConversionUnit = 'KC' then @UnitValue * 3.238315535328652e-4
when @FromConversionUnit = 'FP' and @ToConversionUnit = 'KJ' then @UnitValue * 0.0013558179483314

when @FromConversionUnit = 'J' and @ToConversionUnit = 'BTU' then @UnitValue * 9.478169879134378e-4 
when @FromConversionUnit = 'J' and @ToConversionUnit = 'C' then @UnitValue * 0.2388458966274959
when @FromConversionUnit = 'J' and @ToConversionUnit = 'EV' then @UnitValue * 6.241509479607718e+18
when @FromConversionUnit = 'J' and @ToConversionUnit = 'FP' then @UnitValue * 0.7375621492772656
when @FromConversionUnit = 'J' and @ToConversionUnit = 'KC' then @UnitValue * 2.388458966274959e-4
when @FromConversionUnit = 'J' and @ToConversionUnit = 'KJ' then @UnitValue * 0.001

when @FromConversionUnit = 'KC' and @ToConversionUnit = 'BTU' then @UnitValue * 3.968320164995981
when @FromConversionUnit = 'KC' and @ToConversionUnit = 'C' then @UnitValue * 1000.0
when @FromConversionUnit = 'KC' and @ToConversionUnit = 'EV' then @UnitValue * 2.61319518892216e+22
when @FromConversionUnit = 'KC' and @ToConversionUnit = 'FP' then @UnitValue * 3088.025206594056
when @FromConversionUnit = 'KC' and @ToConversionUnit = 'J' then @UnitValue * 4186.8
when @FromConversionUnit = 'KC' and @ToConversionUnit = 'KJ' then @UnitValue * 4.1868

when @FromConversionUnit = 'KJ' and @ToConversionUnit = 'BTU' then @UnitValue * 0.9478169879134378
when @FromConversionUnit = 'KJ' and @ToConversionUnit = 'C' then @UnitValue * 238.8458966274959
when @FromConversionUnit = 'KJ' and @ToConversionUnit = 'EV' then @UnitValue * 6.241509479607718e+21
when @FromConversionUnit = 'KJ' and @ToConversionUnit = 'FP' then @UnitValue * 737.5621492772656
when @FromConversionUnit = 'KJ' and @ToConversionUnit = 'J' then @UnitValue * 1000.0
when @FromConversionUnit = 'KJ' and @ToConversionUnit = 'KC' then @UnitValue * 0.2388458966274959

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

return(@returnvalue)

end
go



--examples
select dbo.fn_calc_uoc_energy('BTU','C',10)
select dbo.fn_calc_uoc_energy('BTU','EV',10)
select dbo.fn_calc_uoc_energy('BTU','FP',10)
select dbo.fn_calc_uoc_energy('BTU','J',10)
select dbo.fn_calc_uoc_energy('BTU','KC',10)
select dbo.fn_calc_uoc_energy('BTU','KJ',10)

select dbo.fn_calc_uoc_energy('C','BTU',10)
select dbo.fn_calc_uoc_energy('C','EV',10)
select dbo.fn_calc_uoc_energy('C','FP',10)
select dbo.fn_calc_uoc_energy('C','J',10)
select dbo.fn_calc_uoc_energy('C','KC',10)
select dbo.fn_calc_uoc_energy('C','KJ',10)

select dbo.fn_calc_uoc_energy('EV','BTU',10)
select dbo.fn_calc_uoc_energy('EV','C',10)
select dbo.fn_calc_uoc_energy('EV','FP',10)
select dbo.fn_calc_uoc_energy('EV','J',10)
select dbo.fn_calc_uoc_energy('EV','KC',10)
select dbo.fn_calc_uoc_energy('EV','KJ',10)

select dbo.fn_calc_uoc_energy('FP','BTU',10)
select dbo.fn_calc_uoc_energy('FP','C',10)
select dbo.fn_calc_uoc_energy('FP','EV',10)
select dbo.fn_calc_uoc_energy('FP','J',10)
select dbo.fn_calc_uoc_energy('FP','KC',10)
select dbo.fn_calc_uoc_energy('FP','KJ',10)

select dbo.fn_calc_uoc_energy('J','BTU',10)
select dbo.fn_calc_uoc_energy('J','C',10)
select dbo.fn_calc_uoc_energy('J','EV',10)
select dbo.fn_calc_uoc_energy('J','FP',10)
select dbo.fn_calc_uoc_energy('J','KC',10)
select dbo.fn_calc_uoc_energy('J','KJ',10)

select dbo.fn_calc_uoc_energy('KC','BTU',10)
select dbo.fn_calc_uoc_energy('KC','C',10)
select dbo.fn_calc_uoc_energy('KC','EV',10)
select dbo.fn_calc_uoc_energy('KC','FP',10)
select dbo.fn_calc_uoc_energy('KC','J',10)
select dbo.fn_calc_uoc_energy('KC','KJ',10)

select dbo.fn_calc_uoc_energy('KJ','BTU',10)
select dbo.fn_calc_uoc_energy('KJ','C',10)
select dbo.fn_calc_uoc_energy('KJ','EV',10)
select dbo.fn_calc_uoc_energy('KJ','FP',10)
select dbo.fn_calc_uoc_energy('KJ','J',10)
select dbo.fn_calc_uoc_energy('KJ','KC',10)

Rate

3 (1)

You rated this post out of 5. Change rating

Share

Share

Rate

3 (1)

You rated this post out of 5. Change rating