Logo

SQL Server GRAMS Function

Updated 2023-11-09 19:07:48.667000

Description

Use the scalar function GRAMS to convert from drams, grains, grams, hundredweights, ounces, pennyweights, pounds, stones, tonnes, tons, troy pounds or troy ounces to troy pounds.

Syntax

SELECT [westclintech].[wct].[GRAMS] (
  <@Weight, float,>
 ,<@From_scale, nvarchar(4000),>
 ,<@To_scale, nvarchar(4000),>)

Arguments

@Weight

is any real number. @Weight 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 @Weight. @From_scale must be a valid value as specified in weight unit representations. @From_scale must be of a data type that is implicitly convertible to varchar.

@To_scale

is the description of the units for that @Volume is to be converted into. @To_scale must be a valid value as specified in weight unit representations. In addition to grams, @To_scale  can be decigrams, centigrams, milligrams, micrograms, nanograms, picograms, femtograms, attograms, zeptograms, yoctograms, decagrams, hectograms or kilograms. @To_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 weight units of measure into grams:

column 1column 2
grains0.06479891000
drams1.7718452
ounces avoirdupois28.34952
pounds avoirdupois453.59237
stones6350.29318
hundredweights45359.237
tons907184.74
pennyweights1.55517384
ounces troy31.1034768
pounds troy373.2417216
grams1
tonnes1000000

Conversion of grams includes all the standard prefixes with kilo representing 1,000 and yocto representing 10E-24.

Examples

select wct.GRAMS(100, 'lbs', 'kg');

Here is the result set.

column 1
45.359237