CONVERT

Description

Convert an expression of one data type to another. (CONVERT in Transact-SQL).

Sample Source Pattern

Syntax

CONVERT ( data_type [ ( length ) ] , expression [ , style ] )  

Examples

IN -> SqlServer_01.sql
SELECT CONVERT(INT, '1998') as MyDate
OUT -> SqlServer_01.sql
SELECT
CAST('1998' AS INT) as MyDate;

Casting date type to varchar

IN -> SqlServer_02.sql
SELECT CONVERT(varchar, getdate(), 1) AS RESULT;
OUT -> SqlServer_02.sql
SELECT
TO_VARCHAR(CURRENT_TIMESTAMP() :: TIMESTAMP, 'mm/dd/yy') AS RESULT;

Casting date type to varchar with size

IN -> SqlServer_03.sql
SELECT CONVERT(varchar(2), getdate(), 1) AS RESULT;
OUT -> SqlServer_03.sql
SELECT
LEFT(TO_VARCHAR(CURRENT_TIMESTAMP() :: TIMESTAMP, 'mm/dd/yy'), 2) AS RESULT;

The supported formats for dates casts are:

Date formats

Time formats

Date and time formats

Islamic calendar dates

If there is no pattern matching with the current code, it will be formatted to yyyy-mm-dd hh:mm:ss

Known Issues

No issues were found.

No related EWIs.

Last updated