2.2.5.5.4 SQL_VARIANT Values

The SSVARIANTTYPE is a special data type that acts as a place holder for other data types. When a SSVARIANTTYPE is filled with a data value, it takes on properties of the base data type that represents the data value. To support this dynamic change, for those that are not NULL (GEN_NULL) the SSVARIANTTYPE instance has an SSVARIANT_INSTANCE internal structure according to the following definition.

 VARIANT_BASETYPE    =   BYTE      ; data type definition
 VARIANT_PROPBYTES   =   BYTE      ; see below
 VARIANT_PROPERTIES  =   *BYTE     ; see below
 VARIANT_DATAVAL     =   1*BYTE    ; actual data value
            
 SSVARIANT_INSTANCE  =   VARIANT_BASETYPE
                         VARIANT_PROPBYTES
                         VARIANT_PROPERTIES
                         VARIANT_DATAVAL

VARIANT_BASETYPE is the TDS token of the base type.

VARIANT_BASETYPE

 VARIANT_PROPBYTES

 VARIANT_PROPERTIES

GUIDTYPE, BITTYPE, INT1TYPE, INT2TYPE, INT4TYPE, INT8TYPE, DATETIMETYPE, DATETIM4TYPE, FLT4TYPE, FLT8TYPE, MONEYTYPE, MONEY4TYPE, DATENTYPE

0

<not specified>

TIMENTYPE, DATETIME2NTYPE, DATETIMEOFFSETNTYPE

1

1 byte specifying scale

BIGVARBINTYPE, BIGBINARYTYPE

2

2 bytes specifying max length

NUMERICNTYPE, DECIMALNTYPE

2

1 byte for precision followed by 1 byte for scale

BIGVARCHRTYPE, BIGCHARTYPE, NVARCHARTYPE, NCHARTYPE

7

5-byte COLLATION, followed by a 2-byte max length

Note  Data types cannot be NULL when inside a sql_variant. If the value is NULL, the sql_variant itself has to be NULL, but it is not allowed to specify a non-null sql_variant instance and have a NULL value wrapped inside it. A raw collation SHOULD NOT be specified within a sql_variant.<21>

Show: