Technical Article

Calculate Temperature - Most Advanced UOC

,

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

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

Regards,

Vignesh Arulmani

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

--TEMPERATURE
/*============ACRONYM=========
DC - Degrees Celcius
DF - Degrees Fahrenheit
K  - Kelvin
*/
declare @returnvalue float

select @returnvalue = 
case 
when @FromConversionUnit = 'DC' and @ToConversionUnit = 'DF' then @UnitValue * 33.8
when @FromConversionUnit = 'DC' and @ToConversionUnit = 'K' then @UnitValue * 274.15

when @FromConversionUnit = 'DF' and @ToConversionUnit = 'DC' then @UnitValue * -17.22222222222222
when @FromConversionUnit = 'DF' and @ToConversionUnit = 'K' then @UnitValue * 255.9277777777778

when @FromConversionUnit = 'K' and @ToConversionUnit = 'DC' then @UnitValue * -272.15
when @FromConversionUnit = 'K' and @ToConversionUnit = 'DF' then @UnitValue * -457.87

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

return(@returnvalue)

end
go


--examples
select dbo.fn_calc_uoc_temperature('DC','DF',10)
select dbo.fn_calc_uoc_temperature('DC','K',10)

select dbo.fn_calc_uoc_temperature('DF','DC',10)
select dbo.fn_calc_uoc_temperature('DF','K',10)

select dbo.fn_calc_uoc_temperature('K','DC',10)
select dbo.fn_calc_uoc_temperature('K','DF',10)

Rate

1.17 (12)

You rated this post out of 5. Change rating

Share

Share

Rate

1.17 (12)

You rated this post out of 5. Change rating