SQLDescribeCol

ODBC and SQL Server

ODBC and SQL Server

SQLDescribeCol

For executed statements, the Microsoft® SQL Server™ ODBC driver does not need to query the server to describe columns in a result set. In this case, SQLDescribeCol does not cause a server roundtrip. Like SQLColAttribute and SQLNumResultCols, calling SQLDescribeCol on prepared but not executed statements generates a server roundtrip.

When a Transact-SQL statement or statement batch returns multiple result row sets, it is possible for a column, referenced by ordinal, to originate in a separate table or to refer to an entirely different column in the result set. SQLDescribeCol should be called for each set. When the result set changes, the application should rebind data values prior to fetching row results. For more information about handling multiple result set returns, see SQLMoreResults.

Note  When connected to an instance of SQL Server version 4.2x, SQLDescribeCol must create a result set to report column attributes. The SQL Server ODBC driver will append the clause WHERE 1 = 2 to prepared SELECT statements prior to execution. When connected to SQL Server 4.2x, SQLDescribeCol cannot return information about a result set that is generated by a procedure if that procedure has been prepared but not executed.

When connected to any later version of SQL Server, the SQL Server ODBC driver uses the SET FMTONLY statement to reduce server overhead when SQLDescribeCol is called for prepared but not executed statements.

For all versions, column attributes are reported for only the first result set when multiple result sets are generated by a prepared batch of SQL statements.