SqlColType%

Returns the SQL Server datatype for a result column.

Syntax

SqlColType% ( sqlconn%, column% )

where

sqlconn%
Is a SQL Server connection. The value of sqlconn% is returned by SqlOpen%.
column%
Is the number of the column. The first column is number 1.

Returns

An integer value for the datatype of a specified column. If the column number is not in range, -1 is returned.

These are the returned values:

Column
datatype

Returned constant
char SQLCHAR
varchar SQLCHAR
binary SQLBINARY
varbinary SQLBINARY
tinyint SQLINT1
smallint SQLINT2
int SQLINT4
real SQLFLT4
float SQLFLT8
smallmoney SQLMONEY4
money SQLMONEY
decimal SQLDECIMAL
numeric SQLNUMERIC
smalldatetime SQLDATETIM4
datetime SQLDATETIME
image SQLIMAGE
text SQLTEXT

Remarks

The SqlColType% function returns an integer value for the type. Use SqlPrType% to convert the type value into a readable string. This function cannot determine whether a column allows null values.

Example

'Put the statement into the command buffer.
cmd$ = "SELECT name, id, type FROM sysobjects"
Result% = SqlCmd%(Sqlconn%, cmd$)

'Send the statement to SQL Server and start execution.
Result% = SqlExec%(Sqlconn%)

'Process the statement results.
Result% = SqlResults%(Sqlconn%)

'Print the column type.
FOR ColumnNum% = 1 TO 3
   ColumnType% = SqlColType%(Sqlconn%, ColumnNum%)
   PRINT "Column"; ColumnNum%; " type is"; ColumnType%
NEXT ColumnNum%

See Also

SqlColLen%, SqlColName$, SqlData$, SqlDatLen&, SqlNumCols%