• Login

DataSoft Corporation

CONVERT (exp, type [, style ])

The possible types are:

SQL_BIGINT
SQL_BINARY
SQL_BIT
SQL_CHAR
SQL_DATE
SQL_DATETIME
SQL_DECIMAL
SQL_DOUBLE
SQL_FLOAT
SQL_GUID
SQL_INTEGER
SQL_LONGVARCHAR
SQL_NUMERIC
SQL_REAL
SQL_SMALLINT
SQL_TIME
SQL_TIMESTAMP
SQL_TINYINT
SQL_VARCHAR

SQL_LONGVARBINARY

The optional parameter style applies only to the DATETIME data type. Use of the parameter truncates the milliseconds portion of the DATETIME data type. A style value may be either "20" or "120." Both values specify the ODBC canonical format: yyyy-mm-dd hh:mm:ss




The following example converts, respectively, a UBIGINT to a SQL_CHAR, and string data to SQL_DATE, SQL_TIME, and SQL_TIMESTAMP.

SELECT CONVERT(id , SQL_CHAR), CONVERT( '1995-06-05', SQL_DATE), CONVERT('10:10:10', SQL_TIME), CONVERT('1990-10-10 10:10:10', SQL_TIMESTAMP) FROM Faculty

 

The following example converts a string to SQL_DATE then adds 31 to SQL_DATE.

SELECT Name FROM Class WHERE Start_date > CONVERT ('1995-05-07', SQL_DATE) + 31
Thursday, 18 April 2019 Posted in Conversion Functions