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
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Thursday, March 27, 2014 2:29 PM
Points: 990, Visits: 13,439
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


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 3:47 PM
Points: 4,828, Visits: 11,177
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.
Post #1468255
Posted Thursday, June 27, 2013 11:44 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Thursday, March 27, 2014 2:29 PM
Points: 990, Visits: 13,439
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


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 3:47 PM
Points: 4,828, Visits: 11,177
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.
Post #1468426
Posted Friday, June 28, 2013 12:51 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Thursday, March 27, 2014 2:29 PM
Points: 990, Visits: 13,439
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


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 3:47 PM
Points: 4,828, Visits: 11,177
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.
Post #1468444
Posted Friday, June 28, 2013 12:56 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Thursday, March 27, 2014 2:29 PM
Points: 990, Visits: 13,439
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
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Thursday, March 27, 2014 2:29 PM
Points: 990, Visits: 13,439
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


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 3:47 PM
Points: 4,828, Visits: 11,177
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.
Post #1468464
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse