Datatype Mapping

Embedded SQL maps C datatypes to SQL Server datatypes, and vice versa. Conversions are supported for all datatypes except datetime or smalldatetime, money or smallmoney, and decimal or numeric in some instances. The following table lists C datatypes and the SQL Server datatypes they map to. Datatypes that can be converted to datetime or smalldatetime, money or smallmoney, and decimal or numeric are listed with a corresponding T in the respective columns of the following table.


C
datatype

Assigned
SQL Server
datatype


datetime or
smalldatetime


money or
smallmoney


decimal
or numeric

short

smallint

F

F

F

int

smallint

F

F

F

long

int

F

F

F

float

real

F

F

F

double

float

F

F

F

char

varchar[x]1

T

T

T

void *p

binary2

T

T

T

char byte

tinyint

F

F

F

1 For more information, see "Mapping Character Datatypes," later in this chapter.

2 For more information, see "Pointers as Host Variables," later in this chapter.


Output data is truncated if the receiving datatype is too short. This causes an exception (warning), and the SQLCODE field of the SQLCA data structure is set to +1. Input data can be truncated if the receiving SQL Server column is too short. However, in this case, no exception is generated.

Because text datatypes are not allowed in stored procedures, you cannot use C fields that are more than 255 bytes long in static SQL statements that are compiled into access plans.