SQLColAttributes, SQLDescribeCol, and SQLNumResultCols

SQL Server returns information about a results set before it returns the data in the results set. The SQL Server driver returns this information to an application through the SQLColAttributes, SQLDescribeCol, and SQLNumResultCols functions.

When connected to SQL Server 6.x, the SQL Server driver uses the SET FMTONLY statement to retrieve the appropriate information about a results set.

When connected to SQL Server 4.2x, if an application calls any of these functions after a SELECT statement has been prepared and before it has been executed, the SQL Server driver submits the SELECT statement with the clause WHERE 1=2. This forces SQL Server to generate a results set without any rows but with the information about the results set.

Note When connected to SQL Server 4.2x, SQLColAttributes, SQLDescribeCol, and SQLNumResultCols cannot return information about a results set that is generated by a procedure if that procedure has been prepared but not executed. If the SELECT statement is the first statement in a batched statement and SQL Server native grammar is used (no semicolons between statements), the results of these functions are unpredictable. Note also that the word "SELECT" must be the first token in the buffer. If anything precedes the word "SELECT" in the statement to be prepared, "WHERE 1=2" will not be added to the SELECT statement and the information about the results set will not be returned.

In SQL Server 6.5, the ODBC SQL Server driver supports the following driver-specific column attributes in SQLColAttributes.

fDescType parameter pfDesc values
SQL_CA_SS_COLUMN_SSTYPE SQLTEXT

SQLVARBINARY

SQLINTN

SQLVARCHAR

SQLBINARY

SQLIMAGE

SQLCHAR

SQLINT1

SQLBIT

SQLINT2

SQLINT4

SQLMONEY

SQLDATETIME

SQLFLT8

SQLFLTN

SQLMONEYN

SQLDATETIMN

SQLFLT4

SQLMONEY4

SQLDATETIM4

SQLDECIMAL

SQLDECIMALN

SQLNUMERIC

SQLNUMERICN

(Similar to dbcoltype or dbalttype.)

SQL_CA_SS_COLUMN_UTYPE SQLudtTEXT

SQLudtVARBINARY

SQLudtINTN

SQLudtVARCHAR

SQLudtBINARY

SQLudtIMAGE

SQLudtCHAR

SQLudtINT1

SQLudtBIT

SQLudtINT2

SQLudtINT4

SQLudtMONEY

SQLudtDATETIME

SQLudtFLT8

SQLudtFLTN

SQLudtMONEYN

SQLudtDATETIMN

SQLudtSYSNAME

SQLudtTIMESTAMP

SQLudtFLT4

SQLudtMONEY4

SQLudtDATETIM4

SQLudtDECML

SQLudtDECMLN

SQLudtNUM

SQLudtNUMN

(Similar to dbcolutype or dbaltutype.)

SQL_CA_SS_NUM_ORDERS The number of columns in the SQL statement's ORDER BY clause.

(Similar to dbnumorders.)

SQL_CA_SS_COLUMN_ORDER The SELECT list column ID of a column that appears in the SQL statement's ORDER BY clause.

(Similar to dbordercol.)

SQL_CA_SS_COLUMN_VARYLEN TRUE if the column's data can vary in length, otherwise FALSE.

(Similar to dbvarylen.)

SQL_CA_SS_NUM_COMPUTES The number of compute clauses in the current results set.

(Similar to dbnumcompute.)

SQL_CA_SS_COMPUTE_ID The compute ID of a compute row.

(Similar to dbnextrow compute ID return value.)

SQL_CA_SS_COMPUTE_BYLIST The bylist for a compute row.

(Similar to dbbylist.)

SQL_CA_SS_COLUMN_ID The SELECT list column ID for a compute column.

(Similar to dbaltcolid.)

SQL_CA_SS_COLUMN_OP SQLAOPCNT

SQLAOPSUM

SQLAOPAVG

SQLAOPMIN

SQLAOPMAX

SQLAOPANY

SQLAOPNOOP

(Similar to dbaltop.)