DB-Library Datatypes

DB-Library defines datatype tokens for SQL Server data. These datatype constants begin with "SQL" (for example, SQLINT4, SQLCHAR, SQLMONEY). DB-Library also provides type definitions for use in program variable declarations. These type definitions begin with the prefix "DB" (for example, DBINT, DBCHAR, DBMONEY). By using them, you ensure that your program variables will be compatible with SQL Server datatypes. For a list of SQL Server datatypes and the DB-Library program variable types, see Appendix B: DB-Library Datatypes.

The dbconvert function provides a way to convert data from one SQL Server datatype to another. It supports conversion between most datatypes. Since the SQL Server datatypes correspond directly to the DB-Library datatypes, you can use dbconvert widely within your application.

The functions that bind SQL Server result columns to program variables ¾ dbbind and dbaltbind ¾ also provide type conversion.

When the operators SUM and AVG are applied to any column with a small datatype (such as smalldatetime, real, smallmoney, smallint, or tinyint), the server returns results in the larger datatype. For example, suppose that the table sales has a column named price, which is made from the datatype smallmoney, and the following query is executed on this table:

select price from sales

compute sum(price), avg(price), min(price), max(price)

The returned values price, MIN(price), and MAX(price) are of the datatype smallmoney; AVG(price), and SUM(price) are of the datatype money.