Batch wise file generation using BCP
Hi,
There was a requirement where I was asked to generate a CSV files by taking data from a SQL server table. I have done this using BCP command.So currently if i have 10K of records, the Csv files will be generated with all 10K .
For Example:
From TableA, the total number of records fetched is say around 10,000. These 10K records are dumped into a CSV file as 'Abc.Csv'.
Now my requirement is i have to dump data batch wise into a CSV files .i.e from above example i need to have files like Abc1.Csv,Abc2.Csv,Abc3.Csv,Abc4.Csv,Abc5.Csv with 2000 records in each files.I ll not know how many records are their but i have dumped around
2k data in each CSv files.
Is it possible to that with existing BCP commands or do i need to do with a While Loop.
Please advice.
Santhosh
Please have look on the comment
March 5th, 2013 6:16am
Hi Santhosh,
You cannot achive using the existing BCP, insetad you need to use dataflow task with row sampling transformation for your requirements.
Below link helps you in achiving this.
http://www.bimonkey.com/2010/06/the-row-sampling-transformation/
Regards
Naveen
Free Windows Admin Tool Kit Click here and download it now
March 5th, 2013 6:27am
Hi Santhosh,
You can surely achieve this by using programming logic by introducing batch no parameter. You need to use the QueryOut option, and use SELECT TOP rows. Pre-requisite is that you need to have incrementing value column (like identity) to track the row id while
extracting each batch from the table.
Regards,Phaneendra Note: Please vote/mark the post as answered if it answers your question/helps to solve your problem.
March 5th, 2013 7:40am