Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

SSIS Output to csv with differing columns in each row Expand / Collapse
Author
Message
Posted Thursday, June 27, 2013 10:20 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, December 15, 2014 4:34 AM
Points: 1,001, Visits: 13,533
Hi,

I have a requirement to produce a csv file with three differing number of columns.

For example i need to produce a file similar

H,ThisIsAHeaderRow
D,Details,Mr,Test,Person
F,Footer,2

Is this actually possible?

One horrible way i can think of doing it it output strings from sql so there is only 1 column and do it that way but there must be a nicer way than this

select 'H,ThisIsAHeaderRow'

Thanks in advance

John
Post #1468249
Posted Thursday, June 27, 2013 10:31 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 10:17 AM
Points: 5,317, Visits: 12,351
Are the header and footer static or dynamic?


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.

It is better to keep your mouth shut and appear stupid than to open it and remove all doubt. (Mark Twain)
Post #1468255
Posted Thursday, June 27, 2013 11:44 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, December 15, 2014 4:34 AM
Points: 1,001, Visits: 13,533
Header is fixed. Footer is fixed in terms of column numbers but data is dynamic.

Post #1468274
Posted Thursday, June 27, 2013 10:45 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 10:17 AM
Points: 5,317, Visits: 12,351
I would probably use a Script Component to do this - with a single output column.

The Script Component then needs to take care of adding all the delimiters and performing the concatenation, along with the special cases of first and final row.



Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.

It is better to keep your mouth shut and appear stupid than to open it and remove all doubt. (Mark Twain)
Post #1468426
Posted Friday, June 28, 2013 12:51 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, December 15, 2014 4:34 AM
Points: 1,001, Visits: 13,533
OK cheers. One theory I do have is setting 3 data flow tasks all output to different files which have the same output path, hence windows seeing them as the same file. Set overwrite file to off and run them sequentially header,details then footer. That way each data flow task can have a defined output of the number of columns for its type and the mappings should work without hitch. Let's see if it works...

Post #1468443
Posted Friday, June 28, 2013 12:54 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 10:17 AM
Points: 5,317, Visits: 12,351
Animal Magic (6/28/2013)
OK cheers. One theory I do have is setting 3 data flow tasks all output to different files which have the same output path, hence windows seeing them as the same file. Set overwrite file to off and run them sequentially header,details then footer. That way each data flow task can have a defined output of the number of columns for its type and the mappings should work without hitch. Let's see if it works...



Good luck with that! Please let us know whether it works.

A variation on this theme is to write to three separate files and then have a final Execute Process command which does a copy/append of the files to concatenate them - I've successfully used this technique previously.



Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.

It is better to keep your mouth shut and appear stupid than to open it and remove all doubt. (Mark Twain)
Post #1468444
Posted Friday, June 28, 2013 12:56 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, December 15, 2014 4:34 AM
Points: 1,001, Visits: 13,533
That also sounds a good plan! I'll see how it goes today and feed back. Just about too head into work now
Post #1468445
Posted Friday, June 28, 2013 2:27 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, December 15, 2014 4:34 AM
Points: 1,001, Visits: 13,533
The multiple data flow tasks has worked

For anyone that happens upon this thread with the same issue, setup one data flow with a flat file output for your header, so if you have 3 columns in the header map that to three columns in your output.

Then do the details row, adding a new file allows you to do a completely new mapping, so you can add for example 30 columns.

Then do another data flow with your footer row.

Add a variable "OutputFile" and set that as the connection string for all three flat file output files. Turn off the "output headers/first row has header names" and also make sure file overwrite is turned off so that each output appends to the file.

John
Post #1468463
Posted Friday, June 28, 2013 2:29 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 10:17 AM
Points: 5,317, Visits: 12,351
Nice work, well done.


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.

It is better to keep your mouth shut and appear stupid than to open it and remove all doubt. (Mark Twain)
Post #1468464
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse