Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SSIS Sql server 2005 - Adding 0 to day or Month if length is 1

Status
Not open for further replies.

ReportDr00

IS-IT--Management
Mar 2, 2007
194
US

In Derived COlumn Transformation i have fields DCDAY and DCMON that i would like to append "0" infront if length is 1.
Can anyone tell how could i do that?
 
Something like:

REPLICATE("0",2 - LEN(DCDAY)) + DCDAY

If there's not rows with more than 2 characters length in the field DCDAY
 
Remember your output has to be a str value as you want the 0 to precede a single digit 01 as an int will be 1. So in order to accomplish this you first nees to cast your DCDAY to a str. No need to mes with a LEN to test for the current length in you RIGHT(x,2) you will always get the 2 most right characters so 02 would result in 0 even though an incomming dcday 12 would be 012 the right would reduce it to 12.

Code:
RIGHT("0"+ TRIM((DT_STR, 2,1252) [DCDAY]),2)

Paul
---------------------------------------
Shoot Me! Shoot Me NOW!!!
- Daffy Duck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top