Precision Attribute

Because precision and scale are closely related, examples for each are shown together. For more information about precision and scale, see the MSDN topic Precision, Scale, and Length (Transact-SQL).

Table Spec Fields:

  <Fields>
    <DecimalField Name="FIELDA" />
    <DecimalField Name="FIELDB" Precision="20" Scale="4"/>
    <DecimalField Name="FIELDC" Precision="18" Scale="2"/>
    <DecimalField Name="FIELDD" Precision="18" Scale="2"/>
    <DecimalField Name="FIELDE" Precision="18"/>
    <DecimalField Name="FIELDF" Scale="2"/>
    <DecimalField Name="FIELDG" Precision="5"/>
    <DecimalField Name="FIELDH" Scale="0"/>
    <DecimalField Name="FIELDI" Precision="5" Scale="0"/>
    <DecimalField Name="FIELDJ" Precision="38" Scale="37"/>
  </Fields>

When loaded, the defaults are filled:

  • FIELDA(decimal(20,4), not null)

  • FIELDB(decimal(20,4), not null)

  • FIELDC(decimal(18,2), not null)

  • FIELDD(decimal(18,2), not null)

  • FIELDE(decimal(18,4), not null)

  • FIELDF(decimal(20,2), not null)

  • FIELDG(decimal(5,4), not null)

  • FIELDH(decimal(20,0), not null)

  • FIELDI(decimal(5,0), not null)

  • FIELDJ(decimal(38,37), not null)

Because the platform defaults for precision and scale on Table Spec DecimalField elements are different than the Transact-SQL defaults for the decimal data type, it may be necessary to explicitly define precision and scale for stored procedure parameters. In the example, only FIELDC and FIELDD columns on the table match the Transact-SQL defaults. The default precision and scale for decimal is (18,0). For example the stored procedures parameters can be declared as follows. The @FIELDC and @FIELDD parameters accept the defaults. But the other parameters have explicitly declared precision and scale even though the corresponding Table Spec DecimalField elements do not have explicitly specified Precision and Scale attributes. Although those are not defined explicitly on the spec, the platform still specifies a value:

  @ID uniqueidentifier = null output,
  @CHANGEAGENTID uniqueidentifier = null,
  @FIELDA decimal(20,4),
  @FIELDB decimal(20,4),
  @FIELDC decimal,
  @FIELDD decimal,
  @FIELDE decimal(18,4),
  @FIELDF decimal(20,2),
  @FIELDG decimal(25,4),
  @FIELDH decimal(20,0),
  @FIELDI decimal(5,0),
  @FIELDJ decimal(38,37)

The FormField elements could accept the stored procedure parameters' precision and scales by not explicitly specifying values for the Precision and Scale attributes. In those cases, the platform would assume attribute values of -1 for those attributes. Explicitly specifying -1 for Precision and -1 for Scale would have the same effect.

For example, both of the following will pass LoadSpec's validation and defer to the stored procedure parameter's precision and scale:

..
      <common:FormField FieldID="FIELDA"
                        Caption="Field A"
                        Required="true"
                        DataType="Decimal" />
      <common:FormField FieldID="FIELDB"
                        Caption="Field B"
                        Required="true"
                        DataType="Decimal"
                        Precision="-1"
                        Scale="-1"/>
..

But if a different Precision or Scale are specified, LoadSpec will throw an error:

..
      <common:FormField FieldID="FIELDB"
                        Caption="Field B"
                        Required="true"
                        DataType="Decimal"
                        Precision="19"
                        Scale="-1"/>
..

LoadSpec error:

Error.
Field 'FIELDB' has a precision of 19 but the procedure parameter precision is set to 20

If Precision or Scale or both are explicitly declared for the FormField to match the stored procedure precision or scale, that is also acceptable.

..
      <common:FormField FieldID="FIELDB"
                        Caption="Field B"
                        Required="true"
                        DataType="Decimal"
                        Precision="20"
                        Scale="4"/>
..