User Defined Function (UDF) to Convert Length between Feet and Inches in SQL Server

To create a User Defined Function (UDF) that converts length from Feet to Inches, that uses decimal(10,3) data type with precision 10 and scale 3 for input and output length values, use the following command:

CREATE FUNCTION [dbo].[ufn_ft2in] (@ft decimal(10,3))
RETURNS decimal(10,3)
AS
BEGIN
RETURN (@ft * 12)
END

To use this user-defined function (for example to convert 34.651 feet to inches):

SELECT dbo.ufn_ft2in (34.651)

ufn_ft2in

To create a User Defined Function (UDF) that converts length from Inches to Feet, that uses decimal(10,3) data type with precision 10 and scale 3 for input and output length values, use the following command:

CREATE FUNCTION [dbo].[ufn_in2ft] (@in decimal(10,3))
RETURNS decimal(10,3)
AS
BEGIN
RETURN (@in / 12)
END

To use this user-defined function (for example to convert 32.321 inches to feet):

SELECT dbo.ufn_in2ft (32.321)

ufn_in2ft