User Defined Function (UDF) to Convert Volume between Cubic Meters and Cubic Feet in SQL Server

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

CREATE FUNCTION [dbo].[ufn_cbm2cbft] (@cbm decimal(10,4))
RETURNS decimal(10,4)
AS
BEGIN
RETURN (@cbm * 35.3147)
END

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

SELECT dbo.ufn_cbm2cbft (12.7331)

ufn_cbm2cbft

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

CREATE FUNCTION [dbo].[ufn_cbft2cbm] (@cbft decimal(10,4))
RETURNS decimal(10,4)
AS
BEGIN
RETURN (@cbft * 0.0283168)
END

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

SELECT dbo.ufn_cbft2cbm (92.7131)

ufn_cbft2cbm

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="">