WITH temp
AS ( SELECT Month
FROM dbo.test
GROUP BY MONTH
)
SELECT RIGHT(CONCAT( '00',MONTH) , 2)
FROM temp
原理就是先拼出满长度的字符串在用right或者left函数切成指定需要的字符串
用加号拼接容易出坑
select ‘010'+1返回11
select ‘ss'+1返回报错
用cancat拼接不会出现这种问题