I'm trying to add a leading zero to months where there is only a single digit (everything before October). Here's my code:
with tab1 as ( select month(CommitDate) monCommDt , year(CommitDate) yrCommDt from myTable ) select CASE WHEN LEN(monCommDt) = 1 THEN CONCAT('0', monCommDt) ELSE monCommDt END lzCommDt , yrCommDt , LEN(monCommDt) lenCommDt from tab1
Here's the output:
lzCommDt yrCommDt lenCommDt 7 2013 1 7 2013 1 7 2013 1 7 2013 1
Any idea why the leading 0 isn't being added?