Technical Article

Calculate Pressure - Most Advanced UOC

,

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

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

Regards,

Vignesh Arulmani

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

--PRESSURE
/*===============ACRONYM==========
A    - atmosphere
B    - bar
KP   - kilopascal
MMM  - millimeter of mercury
P    - pascal
PSI  - pound per square inch

*/
declare @returnvalue float

select @returnvalue = 
case 
when @FromConversionUnit = 'A' and @ToConversionUnit = 'B' then @UnitValue * 1.01325
when @FromConversionUnit = 'A' and @ToConversionUnit = 'KP' then @UnitValue * 101.325
when @FromConversionUnit = 'A' and @ToConversionUnit = 'MMM' then @UnitValue * 760.1275318829707
when @FromConversionUnit = 'A' and @ToConversionUnit = 'P' then @UnitValue * 101325
when @FromConversionUnit = 'A' and @ToConversionUnit = 'PSI' then @UnitValue * 14.69594940039221

when @FromConversionUnit = 'B' and @ToConversionUnit = 'A' then @UnitValue * 0.9869232667160128
when @FromConversionUnit = 'B' and @ToConversionUnit = 'KP' then @UnitValue * 100
when @FromConversionUnit = 'B' and @ToConversionUnit = 'MMM' then @UnitValue * 750.1875468867217
when @FromConversionUnit = 'B' and @ToConversionUnit = 'P' then @UnitValue * 100000.0
when @FromConversionUnit = 'B' and @ToConversionUnit = 'PSI' then @UnitValue * 14.50377438972831
 
when @FromConversionUnit = 'KP' and @ToConversionUnit = 'A' then @UnitValue * 0.0098692326671601
when @FromConversionUnit = 'KP' and @ToConversionUnit = 'B' then @UnitValue * 0.01
when @FromConversionUnit = 'KP' and @ToConversionUnit = 'MMM' then @UnitValue * 7.501875468867217
when @FromConversionUnit = 'KP' and @ToConversionUnit = 'P' then @UnitValue * 1000.0
when @FromConversionUnit = 'KP' and @ToConversionUnit = 'PSI' then @UnitValue * 0.1450377438972831

when @FromConversionUnit = 'MMM' and @ToConversionUnit = 'A' then @UnitValue * 0.0013155687145324
when @FromConversionUnit = 'MMM' and @ToConversionUnit = 'B' then @UnitValue * 0.001333
when @FromConversionUnit = 'MMM' and @ToConversionUnit = 'KP' then @UnitValue * 0.1333
when @FromConversionUnit = 'MMM' and @ToConversionUnit = 'P' then @UnitValue * 133.3
when @FromConversionUnit = 'MMM' and @ToConversionUnit = 'PSI' then @UnitValue * 0.0193335312615078

when @FromConversionUnit = 'P' and @ToConversionUnit = 'A' then @UnitValue * 9.869232667160128e-6
when @FromConversionUnit = 'P' and @ToConversionUnit = 'B' then @UnitValue * 0.00001
when @FromConversionUnit = 'P' and @ToConversionUnit = 'KP' then @UnitValue * 0.001
when @FromConversionUnit = 'P' and @ToConversionUnit = 'MMM' then @UnitValue * 0.0075018754688672
when @FromConversionUnit = 'P' and @ToConversionUnit = 'PSI' then @UnitValue * 1.450377438972831e-4

when @FromConversionUnit = 'PSI' and @ToConversionUnit = 'A' then @UnitValue * 0.068045961016531
when @FromConversionUnit = 'PSI' and @ToConversionUnit = 'B' then @UnitValue * 0.06894757
when @FromConversionUnit = 'PSI' and @ToConversionUnit = 'KP' then @UnitValue * 6.894757
when @FromConversionUnit = 'PSI' and @ToConversionUnit = 'MMM' then @UnitValue * 51.72360840210053
when @FromConversionUnit = 'PSI' and @ToConversionUnit = 'P' then @UnitValue * 6894.757

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

return(@returnvalue)

end
go


--examples
select dbo.fn_calc_uoc_pressure('A','B' ,10)
select dbo.fn_calc_uoc_pressure('A','KP',10)
select dbo.fn_calc_uoc_pressure('A','MMM',10)
select dbo.fn_calc_uoc_pressure('A','P',10)
select dbo.fn_calc_uoc_pressure('A','PSI',10)

select dbo.fn_calc_uoc_pressure('B','A' ,10)
select dbo.fn_calc_uoc_pressure('B','KP',10)
select dbo.fn_calc_uoc_pressure('B','MMM',10)
select dbo.fn_calc_uoc_pressure('B','P',10)
select dbo.fn_calc_uoc_pressure('B','PSI',10) 

select dbo.fn_calc_uoc_pressure('KP','A' ,10)
select dbo.fn_calc_uoc_pressure('KP','B',10)
select dbo.fn_calc_uoc_pressure('KP','MMM',10)
select dbo.fn_calc_uoc_pressure('KP','P',10)
select dbo.fn_calc_uoc_pressure('KP','PSI',10) 

select dbo.fn_calc_uoc_pressure('MMM','A' ,10)
select dbo.fn_calc_uoc_pressure('MMM','B',10)
select dbo.fn_calc_uoc_pressure('MMM','KP',10)
select dbo.fn_calc_uoc_pressure('MMM','P',10)
select dbo.fn_calc_uoc_pressure('MMM','PSI',10) 

select dbo.fn_calc_uoc_pressure('P','A' ,10)
select dbo.fn_calc_uoc_pressure('P','B',10)
select dbo.fn_calc_uoc_pressure('P','KP',10)
select dbo.fn_calc_uoc_pressure('P','MMM',10)
select dbo.fn_calc_uoc_pressure('P','PSI',10) 

select dbo.fn_calc_uoc_pressure('PSI','A' ,10)
select dbo.fn_calc_uoc_pressure('PSI','B',10)
select dbo.fn_calc_uoc_pressure('PSI','KP',10)
select dbo.fn_calc_uoc_pressure('PSI','MMM',10)
select dbo.fn_calc_uoc_pressure('PSI','P',10)

Rate

1 (6)

You rated this post out of 5. Change rating

Share

Share

Rate

1 (6)

You rated this post out of 5. Change rating