Saturday, January 20, 2018

SQL - Pad a String with leading zero and pick only 2 characters



SELECT  RIGHT(CONCAT('0', '1'), 2)

Output is 01

SELECT  RIGHT(CONCAT('0', '11'), 2)

Output is 11

SELECT concat ( RIGHT(CONCAT('0', '1'), 2),':00')

Output is 01:00

No comments:

Post a Comment

Recently Executed queries

 SELECT     txt.TEXT AS [SQL Statement],     qs.EXECUTION_COUNT [No. Times Executed],     qs.LAST_EXECUTION_TIME AS [Last Time Executed],   ...