User Defined Function (UDF) to Convert Area between Square Meters and Square Yards in SQL Server

To create a User Defined Function (UDF) that converts area from Square Meters to Square Yards, that uses decimal(10,4) data type with precision 10 and scale 4 for input and output area values, use the following command:

CREATE FUNCTION [dbo].[ufn_sqm2sqyd] (@sqm decimal(10,4))
RETURNS decimal(10,4)
AS
BEGIN
RETURN (@sqm * 1.19599)
END

To use this user-defined function (for example to convert 15.764 square meters to square yards):

SELECT dbo.ufn_sqm2sqyd (15.764)

ufn_sqm2sqyd

To create a User Defined Function (UDF) that converts area from Square Yards to Square Meters, that uses decimal(10,4) data type with precision 10 and scale 4 for input and output area values, use the following command:

CREATE FUNCTION [dbo].[ufn_sqyd2sqm] (@sqyd decimal(10,4))
RETURNS decimal(10,4)
AS
BEGIN
RETURN (@sqyd * 0.836127)
END

To use this user-defined function (for example to convert 72.7364 square yards to square meters):

SELECT dbo.ufn_sqyd2sqm (72.7364)

ufn_sqyd2sqm