Im trying to get an equivalent function to the oracle TO_CHAR, for example:
SELECT TO_CHAR(sysdate, 'YYYYMMDD')
will give me
The datepart function in SQLServer doesnt pad the Month and Day portions, spo this gives me:
select cast(datepart(yyyy, getdate()) as varchar) + '_' + cast(datepart(mm, getdate()) as varchar) + '_' + cast(datepart(dd, getdate()) as varchar)
2001_7_5 which is ugly..
Any easy way out rather than writing up some case statement? perhaps padding based on the len of the returned value (all too much work 😉 )
Author of "SQL Server Backup, Recovery & Troubleshooting"
Author of "SQL Server 2k for the Oracle DBA"