Here are the values for the sqltype field in the SQLDA data structure and corresponding Microsoft® SQL Server™ data types for which they can serve as host variables in a FETCH statement or an EXECUTE statement. For each pair of sqltype codes, the odd number type signifies a host variable with a corresponding null indicator variable needed for setting or retrieving null values.
sqltype code | Description | SQL Server data type |
Sample declaration |
---|---|---|---|
392/393 | 26-byte date and time char format corresponds to the formats supported by dbconvert for datetime to/from char1. | datetime, smalldatetime | char date1[27] = Mar 7 1988 7:12PM; |
444/445 | Binary | binary, varbinary, image, timestamp
Note: sqltype 444/445 is automatically used for these SQL Server column types on output. |
char binary1[4097]; |
452/453 | Char string <=254 bytes. Not automatically null-terminated.
Note: Make sure you initialize the full array with nulls when using this type for output. |
char, varchar, or text | char mychar[255]; |
456/457 | Length-prefixed long character field. Not automatically null-terminated. | char, varchar, or text | struct TEXTVAR
{ short len; char data[4097]; } textvar; |
462/463 | Null-terminated string.
Note: Declarations of known length (mychar1) are padded with blanks and a terminating null. Declarations of char pointers (mychar2) are not padded with blanks and the application must ensure sufficient space is allocated. |
char, varchar, or text.
|
char mychar1[41];
char * mychar2;
|
480/481 | 8-byte floating point. | float, real, int, smallint, tinyint, decimal, numeric, money, smallmoney | double mydouble1; |
482/483 | 4-byte floating point. | float, real, int, smallint, tinyint, decimal, numeric, money, smallmoney | float myfloat1; |
496/497 | 4-byte integer. | int, smallint, tinyint, bit | long myint1; |
500/501 | 2-byte integer. | smallint, tinyint, bit | short myshort1; |
1 For more information about datetime conversion, see dbconvert. |
Here are the data type codes returned when using SQLDA structures in DESCRIBE or PREPARE INTO statements.
SQL Server column |
sqltype returned by DESCRIBE or PREPARE INTO |
Comments |
---|---|---|
char, varchar | 452/453 | 452/453 is a COBOL char data type. Not null-terminated. It is easier to use 462/463 from C. |
text | 456/457 | sqllen set to maximum of 32767 for text. |
binary, varbinary, image, timestamp | 444/445 | sqllen set to maximum of 32767 for image. |
smallint, tinyint, bit | 500/501 | |
int | 496/497 | |
float | 480/481 | |
real | 482/483 | |
datetime, smalldatetime | 392/393 | |
decimal, numeric, money, smallmoney | 484/485 | COBOL decimal format. Not supported for FETCH or EXECUTE in ESQL/C (use 480 or 482 instead). Sqllen encoded with scale and precision. Use sqllen &= 0xFF to get just precision. |
DESCRIBE and PREPARE INTO statements are only supported for output columns of SELECT statements. They are not supported for INSERT, UPDATE, or DELETE statements, or for any statement requiring an input host variable.