Click here to Skip to main content
15,885,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have an application which generates a report . The application calls a Stored Procedure where the data from different tables is taken and formatted and dumped in a temporary file. This data is taken by the application , which is bascially dumped in the .csv file. Since the data taken from the temporary table is huge, we are not able to copy the entire data in the CSv.

What I am thinking is that if I divide the entire data in 5 parts i.e 20 % each and then try to populate the csv , i guess i can get the desired result. But the problem is how can take this data in parts ? should i use a loop in my c# code, calling it 5 times,in that case each time I call the stored procedure the data from the beginning will be generated in the SP and will get and overlapping records.

Can any one please suggest how can i proceed with it ? Does any one has a different approach ?

I need a solution at the earliest, the report is to be generated tomorrow after noon.
Posted

 
Share this answer
 
So the problem is not the writing the data to CSV but partitioning the data without overlap so that it can be written to multiple files?

If so.

Initial select of _all_ data into a buffer table

Make sure that each row in your buffer table has a primary key (PK). If your extracted data doesn't have a PK then provide the buffer table with one using an identity column.

Then ...

Select top n rows from your main buffer table into a secondary table (same structure as main buffer) where n is whatever will give you a suitable filesize.

If the secondary table isn't empty...
- Write the content of your secondary table to file.
- Delete from main buffer table inner join on secondary table (this is why the PK is a good idea) to throw away the data just exported.
- Empty the secondary table and repeat for next n rows.

The way you split the load between C# & SQL is up to you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900