user1526892
user1526892

Reputation: 67

SSIS Flat File add trailing spaces to columns

I am developing a SSIS package which concatenates 3 columns and then outputs the result to a flat file.

1st column is a emp_number consists of length 10. The values which I get is "12345" or "123456" or "1234567".

In the output I want is "12345 " or "123456 " or "1234567 "

I have a requirement wherein I need to have columns of fixed size(10), so if the length a value for a particular column is lesser than the expected length I need to pad or fill it with spaces so that the length is matched.

Can you please help.

Upvotes: 1

Views: 1171

Answers (2)

KeithL
KeithL

Reputation: 5594

Similar to iamdave's answer but you need the reverse:

left(yourcolumn + "          ",10) 

There are 10 spaces between the quotes.

if your column is not a string you need to cast it:

left((DT_WSTR,10)yourcolumn + "          ",10) 

Upvotes: 1

iamdave
iamdave

Reputation: 12243

Add a Derived Column transformation that takes the column value, concatenates it to a string made up of 10 spaces (or whatever the total length after padding should be) and then take the rightmost 10 chars using an expression:

RIGHT("0000000000" + yourcol, 10)

Upvotes: 1

Related Questions