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

To create a User Defined Function (UDF) that converts area from Square Meters to Square Feet, 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_sqm2sqft] (@sqm decimal(10,4))
RETURNS decimal(10,4)
AS
BEGIN
RETURN (@sqm * 10.7639)
END

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

SELECT dbo.ufn_sqm2sqft (121.1564)

ufn_sqm2sqft

To create a User Defined Function (UDF) that converts area from Square Feet 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_sqft2sqm] (@sqft decimal(10,4))
RETURNS decimal(10,4)
AS
BEGIN
RETURN (@sqft * 0.092903)
END

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

SELECT dbo.ufn_sqft2sqm (424.1964)

ufn_sqft2sqm

If the post helped you, please share it:
Pin It

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">