user1709091
user1709091

Reputation:

SSIS Derived Column how to format my month display?

I have a column named [Month] which has the months as such..

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

What I want to be able to do is for the first 1-9 is add a 0 so that they read...

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

How would I do this via a derived column? (running SQL Server 2012)

Thanks for your help.

Upvotes: 0

Views: 425

Answers (4)

user2724280
user2724280

Reputation:

after add derived column in expression write this code

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

Upvotes: 2

Justin
Justin

Reputation: 9724

Data:

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

Derived column code:

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

Result:

enter image description here

Upvotes: 1

John Bingham
John Bingham

Reputation: 2006

select 
    case 
       when [Month] < 10 then '0' 
                         else '' 
    end + ltrim(rtrim(cast([Month] as varchar))) 

Upvotes: 0

Milen
Milen

Reputation: 8867

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

Upvotes: 0

Related Questions