Data type mapping from the OLE DB provider to SQL Server defines the allowed comparisons and expressions, and the valid explicit conversions that involve remote data. The mapping is shown in the table that follows.
The type validity for remote table columns in expressions can be summarized by the following rule: A remote column value is valid in a Transact-SQL expression if the corresponding mapped SQL Server data type in the Data Type Mapping table is valid in the same context.
For example, consider the expression: local_column OPERATOR remote_column. In this expression, local_column is a local table column and remote_column is a remote table column. The expression is valid if OPERATOR is a valid operator for the data type of the local column and for the data type to which the DBTYPE of remote_column maps.
Similarly, CAST(remote_column AS data_type_1) is allowed if the DBTYPE of remote_column maps to the SQL Server system data type data_type_2 and explicit conversion from data_type_2 to data_type_1 is allowed. For example, a column of data type DBTYPE_DATE on the provider side can be converted to a datetime column in SQL Server. However, the DBTYPE_DATE data cannot be converted directly to varchar.
The following table shows the data type mapping table. By using the DBTYPE indicator and its DBCOLUMNFLAGS value of a column, you can find the corresponding SQL Server data type.
|
DBTYPE
|
DBCOLUMNFLAGS
|
SQL Server data type
|
|---|
|
DBTYPE_I1
|
|
numeric(3, 0)1
|
|
DBTYPE_I2
|
|
smallint
|
|
DBTYPE_I4
|
|
int
|
|
DBTYPE_I8
|
|
bigint
|
|
DBTYPE_UI1
|
|
tinyint
|
|
DBTYPE_UI1
|
|
numeric(5,0)
|
|
DBTYPE_UI1
|
|
numeric(10,0)
|
|
DBTYPE_UI1
|
|
numeric(20,0)
|
|
DBTYPE_R4
|
|
float
|
|
DBTYPE_R8
|
|
real
|
|
DBTYPE_NUMERIC
|
|
numeric
|
|
DBTYPE_DECIMAL
|
|
decimal
|
|
DBTYPE_CY
|
|
money
|
|
DBTYPE_BSTR
|
DBCOLUMNFLAGS_ISLONG = true
|
ntext
|
|
DBTYPE_BSTR
|
DBCOLUMNFLAGS_ISFIXEDLENGTH = true
|
nchar
|
|
DBTYPE_BSTR
|
DBCOLUMNFLAGS_ISFIXEDLENGTH = false
|
nvarchar
|
|
DBTYPE_IDISPATCH
|
|
Error
|
|
DBTYPE_ERROR
|
|
Error
|
|
DBTYPE_BOOL
|
|
bit
|
|
DBTYPE_VARIANT
|
|
nvarchar(4000)
|
|
DBTYPE_IUNKNOWN
|
|
Error
|
|
DBTYPE_GUID
|
|
uniqueidentifier
|
|
DBTYPE_BYTES
|
DBCOLUMNFLAGS_ISLONG = true or maximum column size > 8,000 bytes.
|
image
|
|
DBTYPE_BYTES
|
DBCOLUMNFLAGS_ISLONG = true and column size is unlimited length.
|
varbinary(max)
|
|
DBTYPE_BYTES
|
DBCOLUMNFLAGS_ISROWVER = true, DBCOLUMNFLAGS_ISFIXEDLENGTH = true, and column size = 8
|
timestamp
|
|
DBTYPE_BYTES
|
DBCOLUMNFLAGS_ISFIXEDLENGTH = true
|
binary
|
|
DBTYPE_BYTES
|
DBCOLUMNFLAGS_ISFIXEDLENGTH = false
|
varbinary
|
|
DBTYPE_STR
|
DBCOLUMNFLAGS_ISFIXEDLENGTH = true
|
char
|
|
DBTYPE_ STR
|
DBCOLUMNFLAGS_ISFIXEDLENGTH = false
|
varchar
|
|
DBTYPE_STR
|
DBCOLUMNFLAGS_ISLONG = true or maximum column size > 8,000 characters.
|
text
|
|
DBTYPE_STR
|
DBCOLUMNFLAGS_ISLONG = true and column size is unlimited length.
|
varchar(max)
|
|
DBTYPE_WSTR
|
DBCOLUMNFLAGS_ISFIXED
|
nchar
|
|
DBTYPE_WSTR
|
DBCOLUMNFLAGS_ISFIXEDLENGTH = false
|
nvarchar
|
|
DBTYPE_WSTR
|
DBCOLUMNFLAGS_ISLONG = true or maximum column size > 4,000 characters.
|
ntext
|
|
DBTYPE_WSTR
|
DBCOLUMNFLAGS_ISLONG = true and column size is unlimited length.
|
nvarchar(max)
|
|
DBTYPE_UDT
|
|
Equivalent SQL Server user-defined type, if one is registered.
|
|
DBTYPE_DATE
|
|
date, datetime, datetime2, datetimeoffset
|
|
DBTYPE_DBDATE
|
|
date, datetime, datetime2, datetimeoffset (Compatibility level is less than 9.0.)
|
|
DBTYPE_DBTIME
|
|
time, datetime, datetime2, datetimeoffset
|
|
DBTYPE_DBTIME_EX
|
|
time, datetime2, datetimeoffset
|
|
DBTYPE_DBTIMESTAMP
|
|
time, date, datetime2, datetimeoffset, datetime
|
|---|
|
DBTYPE_DBTIMESTAMP
|
|
time, date, datetime2, datetimeoffset
|
|
DBTYPE_DBTIMESTAMP
|
|
time, date, datetime2, datetimeoffset
|
|
DBTYPE_ARRAY
|
|
Error
|
|
DBTYPE_BYREF
|
|
Ignored
|
|
DBTYPE_VECTOR
|
|
Error
|
|
DBTYPE_RESERVED
|
|
Error
|
|
DBTYPE_XML
|
|
xml (Allowed only in pass-through queries.)
|
1 numeric(p,s) indicates the SQL Server data type numeric with precision p and scale s.
Note: |
|---|
|
If the data must be converted to a SQL Server data type that is different from the shown default, an explicit conversion, by using either the CAST or CONVERT function, is required. For more information, see CAST and CONVERT (Transact-SQL).
|
The DBTYPE indicator and DBCOLUMNFLAGS value information comes from the provider through either the COLUMNS schema rowset or through the IColumnsInfo interface. For the COLUMNS schema rowset, the DATA_TYPE and COLUMN_FLAGS columns represent the DBTYPE and DBCOLUMNFLAGS values. For the IColumnsInfo::GetColumnInfo interface, the wType and dwFlags members of the DBCOLUMNINFO structure represent these values.