Logo

SQL Server GALLONS Function

Updated 2023-11-09 16:14:36.370000

Description

Use the scalar function GALLONS to convert from barrels (US beer barrels), bbl (oil barrel), bushels, cubic feet, cubic inches, cubic meters, cubic miles, cubic yards, cups, dry pints, dry quarts, fluid drams, fluid ounces, gallons, gills, imperial gallons, imperial gills, imperial pints, imperial quarts, liters, pecks, pints, quarts, steres, tablespoons or teaspoons to gallons.

Syntax

SELECT [westclintech].[wct].[GALLONS] (
  <@Volume, float,>
 ,<@From_scale, nvarchar(4000),>);

Arguments

@Volume

is any real number. @Volume is an expression of type float or of a type that can be implicitly converted to float.

@From_scale

is the description of the units for @Volume. @From_scale must be a valid value as specified in volume unit representations. @From_scale must be of a data type that is implicitly convertible to varchar.

Return Type

float

Remarks

The following table is a representation of the conversion of one of the volume units of measure into gallons:

column 1column 2
teaspoon0.001302083
tablespoon0.00390625
fluid dram0.000976563
fluid ounce0.0078125
cup0.0625
pint0.125
quart0.25
gallon1
cubic inch0.004329004
cubic foot7.48051948
cubic yard201.974026
cubic mile1.10112E+12
imperial ounce0.00750594
imperial pint0.150118803
imperial quart0.300237605
imperial gallon1.20095042
barrel (beer)31
barrel (oil)42
bushel9.30917797
gill0.03125
imperial gill0.037529701
peck2.32729449
dry pint0.145455899
dry quart0.290911797
stere264.172052
liter0.264172052
cubic meter264.172052

Conversion of metric values (liters and cubic meters) includes all the standard prefixes with kilo representing 1,000 and yocto representing 10E-24.

Examples

select wct.GALLONS(1, 'quart');

Here is the result set.

column 1
0.25