SQL Server to_char conversion

When converting from oracle to SQL server you may struggle with Oracle to_char() and to_date() convertions.  SQL server handles this differently.  You have to used fixed types or you can use some clever madness.

For YYYYMMDDHH24MISS :

(SELECT REPLACE(REPLACE(REPLACE(CONVERT(VARCHAR(19), CONVERT(DATETIME, getdate(), 112), 126), ‘-‘, ”), ‘T’, ”), ‘:’, ”))

For DD/MM/YYYY HH24:MI:SS :

(select CONVERT(VARCHAR(10), GETDATE(), 103) + ‘ ‘ + convert(VARCHAR(8), GETDATE(), 14))

Leave a Reply

Your email address will not be published. Required fields are marked *