Is there anyway to optimize this horrible inefficient UDF in SQL Server 08. I am fairly new to UDF's and especially looking at them for optimizations.
UPDATE: Should I be sending a column to a function like this if I wanted to perform it on each row and each column in a query? Is there a better way to go about this?
Thank You
** @value(float) and @fieldname(varchar(40)) are input parameters **
BEGIN
DECLARE @UT integer, @FRM integer, @TO integer, @FACTOR float
select @UT = [UF_UT_ID] FROM dbo.UNIT_FIELDS where [UF_FIELD]=@fieldName
select @FRM = [UT_UN_ID_INTERNAL_UNITS] from dbo.UNIT_TYPES where [UT_ID]=@UT
select @TO = [UT_UN_ID_DISPLAY_UNITS] from dbo.UNIT_TYPES where [UT_ID]=@UT
select @FACTOR = [UC_SLOPE] from dbo.UNIT_CONVERSIONS where [UC_UN_ID_UNIT_FROM]=@FRM and [UC_UN_ID_UNIT_TO]=@TO
-- Return the result of the function dbo.
RETURN @FACTOR*@value
END