June 25, 2018 at 5:20 am
Hi,
I have a table with 200 000 records, I need to send a file with 50 000 records. I'm using MS SQL 2016. I'm not sure how to go about it but I think my logic will be on my SSIS Package. help.
June 25, 2018 at 5:35 am
I need to produce a file with 50k records/batch for whatever number of records in the table, the table currently it's at 200k, it could have been 130k, then I would have sent 3 files, 50,50 then 30k.
June 25, 2018 at 6:07 am
This is a simp,e description opf the steps you need to do; as I don't have a lot of detail to go on.
OK, I would firstly create a Execute SQL Statement task, and return the number of rows to a variable. In your package as well, you'll also need for few more further variables for the FileName, Offset and Fetch values, and another for your dynamic SQL.
The SQL variable will need to be something like:="SELECT YourColumns FROM YourTable WHERE YourWhereCriteria ORDER BY YourIDColumn OFFSET " + (DT_WSTR,10) user::Offset + " ROWS FETCH NEXT " + (DT_WSTR,10) user::Fetch + " ROWS ONLY;"
(this is UNTESTED code)
Create a For Loop container, and set it to loop while the value of Off Set is less than the value of your total rows variable. In there, create your dataflow, and use the value of your dynamic SQL as the source. Then export that data to your file (which'll have a dynamic name).
Then, after the dataflow, use a Expression task to increase the value of your Offset variable by your Fetch Variable's value, and then another to update the name of your filename (or have the filename as an expression, derived off the valyue of OFFSET). Your container will then loop until all the rows are processed, generating a new file each time.
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
June 25, 2018 at 6:26 am
sirkinghorse - Monday, June 25, 2018 5:20 AMHi,
I have a table with 200 000 records, I need to send a file with 50 000 records. I'm using MS SQL 2016. I'm not sure how to go about it but I think my logic will be on my SSIS Package. help.
Why would you need to limit the file to only 50,000 rows?
--Jeff Moden
Change is inevitable... Change for the better is not.
June 25, 2018 at 6:32 am
Batches of 50k, that's the requirements. if I have 200k in the table, they want that in a file, but 50k per file.
June 25, 2018 at 6:43 am
sirkinghorse - Monday, June 25, 2018 6:32 AMBatches of 50k, that's the requirements. if I have 200k in the table, they want that in a file, but 50k per file.
Ah... got it. Thank you for the feedback. I hate such artificial limits.
Did Thom's suggestion do it for you or do you still need help?
--Jeff Moden
Change is inevitable... Change for the better is not.
November 22, 2018 at 5:59 am
I've done something similar a few months ago ... however I just used a BCP out command to generate the files inside SSIS.
The overall flow was something like:
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply