Link to home
Start Free TrialLog in
Avatar of coventri
coventri

asked on

How to add header and trailer to text file using ssis

I want to add header and trailer to text file using ssis.
The header and trailer must be in different rows.
I attched ssis package which I created.But i  did not get correct result.

can any one check and give right suggestions

Thanks,
coventri
Package.txt
Avatar of Steve Hogg
Steve Hogg
Flag of United States of America image

There is some promise in using the approach in your package. A UNION might accopmplish this if you write your SQL to produce the "exact" same columns. Instead of asking SSIS to build the file lines for you, you would need to create them in your SQL.
For example:
select  1 as rownum, col1 + col2 + cast(sum(col3) as varchar(30)) as fileline from ... (header row)
union all
select 2 as rownum, col3 + col5 + col6 + col9 + col19 + col33 as fileline from ... (detail rows)
union all
select 3 as rownum, .... as fileline from ... (footer / trailer)
Avatar of coventri
coventri

ASKER

Hi,

I am using oledb source in ssis(sql command as data acess mode) to prepare data .How can  I pass
col 2 as variable in header row

Thanks
coventri
ASKER CERTIFIED SOLUTION
Avatar of Steve Hogg
Steve Hogg
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You could export a seperate header.txt and trailer.txt file, then use a DOS COPY command to append them all together.
COPY Header.TXT + Data.TXT + Trailer.TXT FinalFile.TXT