473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

For XML Explicit Syntax to Normalize a table

I am trying to write a FOR XML EXPLICIT query for the following table:

GameName Count1 Count2 CountTotal Percent1 Percent2 PercentTotal
---------- ----------- ----------- ----------- ----------- ----------- ------------
Clinker 44 55 99 45 55 100
Skullcap 12 88 100 10 90 100


What I want to create is:

<root>
<games GameName="Clinker">
<count Count1="44" Count2="55" CountTotal="99" />
<percent Percent1="45" Percent2="55" PercentTotal="100" />
</games>
<games GameName="Skullcap">
<count Count1="12" Count2="88" CountTotal="100"/>
<percent Percent1="10" Percent2="90" PercentTotal="100"/>
</games>
</root>

Using the following SQL query:
Select 1 As Tag,
Null As Parent,
GameName As [Games!1!GameName],
Null AS [Games!2!Count1],
Null AS [Games!2!Count2],
Null AS [Games!2!CountTotal],
Null AS [Games!3!Percent1],
Null As [Games!3!Percent2],
Null AS [Games!3!PercentTotal]
From Games
UNION ALL
Select
2,
1,
Null,
Count1,
Count2,
CountTotal,
Null,
Null,
Null
From Games
UNION ALL
Select
3,
2,
Null,
Null,
Null,
Null,
Percent1,
Percent2,
PercentTotal
From Games
FOR XML Explicit



What I am getting is:


<Games GameName="Clinker" />
<Games GameName="Skullcap">
<Games Count1="44" Count2="55" CountTotal="99" />
<Games Count1="12" Count2="88" CountTotal="100" />
<Games Percent1="45" Percent2="55" PercentTotal="100" />
<Games Percent1="10" Percent2="90" PercentTotal="100" />
</Games>

Which of course isn't well formed XML.

Can anyone give me a clue on how to write this query?

Thanks!

Brandon_Forest@sbcglobal.net
Jan 13 '08 #1
0 821

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Christos TZOTZIOY Georgiou | last post by:
I found at least one case where decombining and recombining a unicode character does not result in the same character (see at end). I have no extensive knowledge about Unicode, yet I believe that...
6
by: Christoph Bartoschek | last post by:
Hi, gcc 3.4 rejects the following program: class T { public: T() : a(3) {} explicit T(T const & other) : a(other.a) {} private: int a;
3
by: Rick Brown | last post by:
I have a table with fields named Part1, Part2, Part3 etc. I get the following error message when I try to load the table via code. Error = "Item not found in this collection" I figure the...
12
by: Steve W. | last post by:
I just read the section (and did the exercise) in the C# Step by Step book that covers Explict Interface Implementation (where you specify in the method implementation the specific interface that...
31
by: Michael C | last post by:
If a class inherits from another class, say Form inherits from control, then I can assign the Form to a variable of type Control without needing an explicit conversion, eg Form1 f = new Form1();...
4
by: Nathan Benefield | last post by:
I currently have a spreadsheet tracking votes on legislation in a matrix type format. It is something like this Name Act1 Veto1 Act1A Jones yes No Yes Johnson Yes ...
8
by: bbcrock | last post by:
I have three tables with a relationship I've never worked with before. Can anyone suggest/comment on the best way to create a third normal form relationship between these tables? The tables...
9
by: Peter Bengtsson | last post by:
In UTF8, \u0141 is a capital L with a little dash through it as can be seen in this image: http://static.peterbe.com/lukasz.png I tried this: '' I was hoping it would convert it it 'L'...
12
by: Rahul | last post by:
Hi Everyone, I have the following code and i'm able to invoke the destructor explicitly but not the constructor. and i get a compile time error when i invoke the constructor, why is this so? ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.