Welcome Guest! Log in
×

Notice

The forum is in read only mode.
Stambia versions 2.x, 3.x, S17, S18, S19 and S20 are reaching End of Support January, 15th, 2024. Please consider upgrading to the supported Semarchy xDI versions. See Global Policy Support and the Semarchy Documentation.

The Stambia User Community is moving to Semarchy! All the applicable resources have already been moved or are currently being moved to their new location. Read more…

Topic-icon Question How to sort data in a xml file target?

More
28 Nov 2016 11:14 - 28 Nov 2016 11:15 #1 by letancel
How to sort data in a xml file target? was created by letancel
Hi,

I'm looking for a way to sort (order by) data when I load them from a MS SQL table to a xml file.
I didn't find any option in the Integration Template, how can I do it?

Thanks,
Last edit: 28 Nov 2016 11:15 by letancel.
More
28 Nov 2016 14:41 - 28 Nov 2016 14:43 #2 by Cyril Dussud
Replied by Cyril Dussud on topic How to sort data in a xml file target?
Hi,

To order the data when loading an XML file, the idea is to set the rule on the repetition key generating the XML node.
For this, concatenate all the source columns you would have put in the ORDER BY SQL query.

As an example, I am ordering here the data by CUS_TITLE and CUS_ID:


The value used for the repetition key is:
CONCAT (DIM_CUSTOMER.CUS_TITLE,DIM_CUSTOMER.CUS_ID)

Note:
Does this help to perform what you wanted?
Attachments:
Last edit: 28 Nov 2016 14:43 by Cyril Dussud.
More
28 Nov 2016 14:56 - 28 Nov 2016 15:15 #3 by letancel
Replied by letancel on topic How to sort data in a xml file target?
Hi,

Yes its works!
But, how can I sort a string value in DESC order?

Thanks
Last edit: 28 Nov 2016 15:15 by letancel.
More
30 Nov 2016 17:00 #4 by Cyril Dussud
Replied by Cyril Dussud on topic How to sort data in a xml file target?
Hi,

For more advanced sorting, you can use a stage and the Analytic / Ranking functions of your the Database to generate a key corresponding to your sort for each of your lines.

Here is an example with Microsoft SQL Server:

1. Add a stage between your source table and your target XML File
2. Map your source fields in the stage
3. Add a new column on the stage, with the analytic function corresponding to the wanted sort as expression
4. Map this column to the repetition key of your XML Node



The expression used in the sortKey column here is:
ROW_NUMBER() OVER (ORDER BY CUS_NAME DESC)

Explanation:
This expression will tell SQL Server to generate a number for each row, with the order defined in the condition.
We are then using this "sorted" column on the XML Node repetition key.

Please refer to the documentation of your database to find the correct function / syntax to perform this.
For SQL Server: msdn.microsoft.com/en-us/library/ms186734.aspx
Attachments:
More
30 Nov 2016 17:16 #5 by letancel
Replied by letancel on topic How to sort data in a xml file target?
Hi,

Thanks for your answer.

That's exactly what I did because the CONCAT was too complicated in my case.