0

我有一个名为 [Month] 的列,其中包含月份。

1
2
3
4
5
6
7
8
9
10
11
12

我想要做的是前 1-9 是添加一个 0 以便他们阅读......

01
02
03
04
05
06
07
08
09
10
11
12 

我将如何通过派生列做到这一点?(运行 SQL Server 2012)

谢谢你的帮助。

4

4 回答 4

2

after add derived column in expression write this code

RIGHT("00"+(DT_WSTR,2)Month,2)

于 2013-09-18T04:00:24.330 回答
1

数据:

1, 2, 3, 4, 10, 15, 100

派生列代码:

Month < 10 ? "0" + (DT_WSTR,3)Month : (DT_WSTR,3)Month

结果:

在此处输入图像描述

于 2013-09-18T08:59:39.743 回答
0

尝试:select right ('00'+ltrim(str([Month])),2 )

于 2013-09-17T22:03:57.170 回答
0
select 
    case 
       when [Month] < 10 then '0' 
                         else '' 
    end + ltrim(rtrim(cast([Month] as varchar))) 
于 2013-09-17T22:06:45.557 回答