SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


XML Output - Fields in reverse order?


XML Output - Fields in reverse order?

Author
Message
Rob-350472
Rob-350472
SSChasing Mays
SSChasing Mays (635 reputation)SSChasing Mays (635 reputation)SSChasing Mays (635 reputation)SSChasing Mays (635 reputation)SSChasing Mays (635 reputation)SSChasing Mays (635 reputation)SSChasing Mays (635 reputation)SSChasing Mays (635 reputation)

Group: General Forum Members
Points: 635 Visits: 684
Guys,

For some reason the XML output given by SSRS 2008 seems to put the fields in reverse order, has anyone come across this, it seems very wierd. For example, take this simple code:

SELECT
1 as ID,
'ABC Capital' as Firm_Name,
'123 The Lane' as Firm_Address_1,
'London' as Firm_City,
100000 as AUM_USD,
'Retail, Consumer Goods' as Industry

UNION

SELECT
2 as ID,
'AXyZ Capital' as Firm_Name,
'333 The Lane' as Firm_Address_1,
'New York' as Firm_City,
9999 as AUM_USD,
'Food' as Industry

UNION

SELECT
3 as ID,
'ABC Capital' as Firm_Name,
'1 The Lane' as Firm_Address_1,
'Milan' as Firm_City,
555 as AUM_USD,
'Agriculture' as Industry


The industry field comes first and the ID field last.

I suppose this doesn't matter but conceptually it just looks odd.

The output given by this:

SELECT * FROM
(
SELECT
1 as ID,
'ABC Capital' as Firm_Name,
'123 The Lane' as Firm_Address_1,
'London' as Firm_City,
100000 as AUM_USD,
'Retail, Consumer Goods' as Industry

UNION

SELECT
2 as ID,
'AXyZ Capital' as Firm_Name,
'333 The Lane' as Firm_Address_1,
'New York' as Firm_City,
9999 as AUM_USD,
'Food' as Industry

UNION

SELECT
3 as ID,
'ABC Capital' as Firm_Name,
'1 The Lane' as Firm_Address_1,
'Milan' as Firm_City,
555 as AUM_USD,
'Agriculture' as Industry
)x
FOR XML PATH

In Management Studio, seems to make much more sense- it's in the same order as the select (not to mention the formatting).

Has anyone else come across this, if so did they just put up with it, not use XML output from SSRS or do something different?

Thanks in advance!
Steven Willis
Steven Willis
SSC Eights!
SSC Eights! (823 reputation)SSC Eights! (823 reputation)SSC Eights! (823 reputation)SSC Eights! (823 reputation)SSC Eights! (823 reputation)SSC Eights! (823 reputation)SSC Eights! (823 reputation)SSC Eights! (823 reputation)

Group: General Forum Members
Points: 823 Visits: 1721
This is what I got when I used your code in SSMS as is. It looks correct for me. So perhaps something specific to your database settings (like collation) is making it sort differently?


<row>
<ID>1</ID>
<Firm_Name>ABC Capital</Firm_Name>
<Firm_Address_1>123 The Lane</Firm_Address_1>
<Firm_City>London</Firm_City>
<AUM_USD>100000</AUM_USD>
<Industry>Retail, Consumer Goods</Industry>
</row>
<row>
<ID>2</ID>
<Firm_Name>AXyZ Capital</Firm_Name>
<Firm_Address_1>333 The Lane</Firm_Address_1>
<Firm_City>New York</Firm_City>
<AUM_USD>9999</AUM_USD>
<Industry>Food</Industry>
</row>
<row>
<ID>3</ID>
<Firm_Name>ABC Capital</Firm_Name>
<Firm_Address_1>1 The Lane</Firm_Address_1>
<Firm_City>Milan</Firm_City>
<AUM_USD>555</AUM_USD>
<Industry>Agriculture</Industry>
</row>


Steven Willis
Steven Willis
SSC Eights!
SSC Eights! (823 reputation)SSC Eights! (823 reputation)SSC Eights! (823 reputation)SSC Eights! (823 reputation)SSC Eights! (823 reputation)SSC Eights! (823 reputation)SSC Eights! (823 reputation)SSC Eights! (823 reputation)

Group: General Forum Members
Points: 823 Visits: 1721
You can check the collation on your db with:
(code from Pinal Dave)



SELECT
c.name
,c.collation_name
FROM
sys.columns c
WHERE
OBJECT_ID IN
(
SELECT
OBJECT_ID
FROM
sys.objects o
WHERE
type = 'U'
AND o.name = 'YourTableName'
)




Just for reference, on my machine the collation is 'SQL_Latin1_General_CP1_CI_AS'.

 
Rob-350472
Rob-350472
SSChasing Mays
SSChasing Mays (635 reputation)SSChasing Mays (635 reputation)SSChasing Mays (635 reputation)SSChasing Mays (635 reputation)SSChasing Mays (635 reputation)SSChasing Mays (635 reputation)SSChasing Mays (635 reputation)SSChasing Mays (635 reputation)

Group: General Forum Members
Points: 635 Visits: 684
I meant to reply yesterday afternoon, I stumbled on the solution, sort of by accident!

On the table in question 'DataElemetStyle' was just left at the default of auto, changing this to Element had two impacts:

1. The XML was far nicer to read - not just one massive block for each row
2. The fields were in the correct order

It does seem odd that in the default setting it looks hideous and the fields are inverted in their order, however, an element structure seems to cure this Smile

Odd but there you go, I wonder if anyone else can replicate this or if it's just me!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search