SSVARIANT Structure in SQL Server Native Client
Applies to: SQL Server Azure SQL Database Azure SQL Managed Instance Azure Synapse Analytics Analytics Platform System (PDW)
The SSVARIANT structure, which is defined in sqlncli.h, corresponds to a DBTYPE_SQLVARIANT value in the SQL Server Native Client OLEDB provider.
SSVARIANT is a discriminating union. Depending on the value of the vt member, the consumer can determine which member to read. vt values correspond to SQL Server data types. Therefore, the SSVARIANT structure can hold any SQL Server type. For more information about the data structure for standard OLE DB types, see Type Indicators.
Remarks
When DataTypeCompat==80, several SSVARIANT subtypes become strings. For example, the following vt values will appear in SSVARIANT as VT_SS_WVARSTRING:
VT_SS_DATETIMEOFFSET
VT_SS_DATETIME2
VT_SS_TIME2
VT_SS_DATE
When DateTypeCompat == 0, these types will appear in their native form.
For more information about SSPROP_INIT_DATATYPECOMPATIBILITY, see Using Connection String Keywords with SQL Server Native Client.
The sqlncli.h file contains variant access macros that simplify dereferencing the member types in the SSVARIANT structure. An example is V_SS_DATETIMEOFFSET, which you can use as follows:
memcpy(&V_SS_DATETIMEOFFSET(pssVar).tsoDateTimeOffsetVal, pDTO, cbNative);
V_SS_DATETIMEOFFSET(pssVar).bScale = bScale;
For the complete set of access macros for each member of the SSVARIANT structure, refer to the sqlncli.hi file.
The following table describes the members of the SSVARIANT structure:
Member | OLE DB type indicator | OLE DB C data type | vt value | Comments |
---|---|---|---|---|
vt | SSVARTYPE | Specifies the type of value contained in the SSVARIANT struct. | ||
bTinyIntVal | DBTYPE_UI1 | BYTE | VT_SS_UI1 | Supports the tinyintSQL Server data type. |
sShortIntVal | DBTYPE_I2 | SHORT | VT_SS_I2 | Supports the smallintSQL Server data type. |
lIntVal | DBTYPE_I4 | LONG | VT_SS_I4 | Supports the intSQL Server data type. |
llBigIntVal | DBTYPE_I8 | LARGE_INTEGER | VT_SS_I8 | Supports the bigintSQL Server data type. |
fltRealVal | DBTYPE_R4 | float | VT_SS_R4 | Supports the realSQL Server data type. |
dblFloatVal | DBTYPE_R8 | double | VT_SS_R8 | Supports the floatSQL Server data type. |
cyMoneyVal | DBTYPE_CY | LARGE_INTEGER | VT_SS_MONEY VT_SS_SMALLMONEY | Supports the money and smallmoneySQL Server data types. |
fBitVal | DBTYPE_BOOL | VARIANT_BOOL | VT_SS_BIT | Supports the bitSQL Server data type. |
rgbGuidVal | DBTYPE_GUID | GUID | VT_SS_GUID | Supports the uniqueidentifierSQL Server data type. |
numNumericVal | DBTYPE_NUMERIC | DB_NUMERIC | VT_SS_NUMERIC | Supports the numericSQL Server data type. |
dDateVal | DBTYPE_DATE | DBDATE | VT_SS_DATE | Supports the dateSQL Server data type. |
tsDateTimeVal | DBTYPE_DBTIMESTAMP | DBTIMESTAMP | VT_SS_SMALLDATETIME VT_SS_DATETIME VT_SS_DATETIME2 | Supports the smalldatetime, datetime, and datetime2SQL Server data types. |
Time2Val | DBTYPE_DBTIME2 | DBTIME2 | VT_SS_TIME2 | Supports the timeSQL Server data type. Includes the following members: tTime2Val (DBTIME2) bScale (BYTE) Specifies the scale for tTime2Val value. |
DateTimeVal | DBTYPE_DBTIMESTAMP | DBTIMESTAMP | VT_SS_DATETIME2 | Supports the datetime2SQL Server data type. Includes the following members: tsDataTimeVal (DBTIMESTAMP) bScale (BYTE) Specifies the scale for tsDataTimeVal value. |
DateTimeOffsetVal | DBTYPE_DBTIMESTAMPOFSET | DBTIMESTAMPOFFSET | VT_SS_DATETIMEOFFSET | Supports the datetimeoffsetSQL Server data type. Includes the following members: tsoDateTimeOffsetVal (DBTIMESTAMPOFFSET) bScale (BYTE) Specifies the scale for tsoDateTimeOffsetVal value. |
NCharVal | No corresponding OLE DB type indicator. | struct _NCharVal | VT_SS_WVARSTRING, VT_SS_WSTRING |
Supports the nchar and nvarcharSQL Server data types. Includes the following members: sActualLength (SHORT) Specifies the actual length for the string to which pwchNCharVal points. Does not include terminating zero. sMaxLength (SHORT) Specifies the maximum length for the string to which pwchNCharVal points. pwchNCharVal (WCHAR *) Pointer to the string. Unused members: rgbReserved, dwReserved, and pwchReserved. |
CharVal | No corresponding OLE DB type indicator. | struct _CharVal | VT_SS_STRING, VT_SS_VARSTRING |
Supports the char and varcharSQL Server data types. Includes the following members: sActualLength (SHORT) Specifies the actual length for the string to which pchCharVal points. Does not include terminating zero. sMaxLength (SHORT) Specifies the maximum length for the string to which pchCharVal points. pchCharVal (CHAR *) Pointer to the string. Unused members: rgbReserved, dwReserved, and pwchReserved. |
BinaryVal | No corresponding OLE DB type indicator. | struct _BinaryVal | VT_SS_VARBINARY, VT_SS_BINARY |
Supports the binary and varbinarySQL Server data types. Includes the following members: sActualLength (SHORT) Specifies the actual length for the data to which prgbBinaryVal points. sMaxLength (SHORT) Specifies the maximum length for the data to which prgbBinaryVal points. prgbBinaryVal (BYTE *) Pointer to the binary data. Unused member: dwReserved. |
UnknownType | UNUSED | UNUSED | UNUSED | UNUSED |
BLOBType | UNUSED | UNUSED | UNUSED | UNUSED |