I'm trying to do the following:
from a very simple SQL select (I need only two fields: Datetime and HRCode ) that returns a large number of records
I need to:
- extract set of 10 records.
- with this 10 records, output an XML fixed format :
<moduloIntermittenti> <Campi> <CFdatorelavoro>1231212313</CFdatorelavoro> <BCbarcodeModello01>ML-15-01</BCbarcodeModello01> <BCbarcodeModello01>ML-15-01</BCbarcodeModello01> <EMmail>email@example.com</EMmail> <ANannullamento></ANannullamento> <CFlavoratore1>HRCode1</CFlavoratore1> <CCcodcomunicazione1 /> <DTdatainizio1>Datetime1</DTdatainizio1> <DTdatafine1 /> <CFlavoratore2>HRCode2</CFlavoratore2> <CCcodcomunicazione2 /> <DTdatainizio2>Datetime2</DTdatainizio2> <DTdatafine2></DTdatafine2> <CFlavoratore3>HRCode3</CFlavoratore3> <CCcodcomunicazione3 /> <DTdatainizio3>Datetime3</DTdatainizio3> <DTdatafine3 /> <CFlavoratore4>HRCode4</CFlavoratore4> <CCcodcomunicazione4 /> <DTdatainizio4>Datetime4</DTdatainizio4> <DTdatafine4></DTdatafine4> <CFlavoratore5>HRCode5</CFlavoratore5> <CCcodcomunicazione5 /> <DTdatainizio5>Datetime5</DTdatainizio5> <DTdatafine5 /> <CFlavoratore6 /> <CCcodcomunicazione6 /> <DTdatainizio6 /> <DTdatafine6 /> <CFlavoratore7 /> <CCcodcomunicazione7 /> <DTdatainizio7 /> <DTdatafine7 /> <CFlavoratore8 /> <CCcodcomunicazione8 /> <DTdatainizio8 /> <DTdatafine8 /> <CFlavoratore9 /> <CCcodcomunicazione9 /> <DTdatainizio9 /> <DTdatafine9 /> <CFlavoratore10 /> <CCcodcomunicazione10 /> <DTdatainizio10 /> <DTdatafine10 /> </Campi> </moduloIntermittenti>
as you can see, the xml is fixed and offers a subset of fields that repeats itself 10 times(adding the number in each node).
I need to take every 10 records from my table, "fill in the blanks" in this xml structure, create an xml file and fire it up as an attachment by email.
After some research, I think the better way to do all of this is using SSIS; but I've no idea how break and create an xml every ten records, keeping in mind that every node has a number.
Thanks in advance for any suggestion
- Moved by Kalman Toth Tuesday, July 16, 2013 8:46 PM SSIS task
You'll be doing most of this in an SSIS For Loop; you may want to ask about the specifics there.
Some tips: To know how many times you'll need to loop, copy the record count of the source table to a variable, then take the Ceiling of that divided by 10.
If you're more comfortable doing that as a SQL task it would be:
Map the result set to your total number of iterations; 102 records will yield 11 iterations, for example.
Now you can loop through with:
Select Top 10 from <tble> where RowNo >= <iteration>
Where <iteration> is the current iteration - 1 through the total number of iterations, incrementing by 10 after each loop
Map the results to an XML file and a send message task. The For Loop will continue until the current iteration is greater than the total number of iterations.
Do note that you may have to copy your data to a temporary table that has an identity field to stand in for RowNo or you can create it by including
row_number() over( order by Datetime ) Rowin your select statement
- Marked as answer by Mike YinMicrosoft contingent staff, Moderator Thursday, July 18, 2013 1:01 AM