473,626 Members | 3,246 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Server 2000 XML Element Order

29 New Member
Hey everyone,

Im trying to create an XML document with specific element order. Here is what I need:
Expand|Select|Wrap|Line Numbers
  1. <invoice_shipment>
  2.   <internal_id/>
  3.   <shipping_cost/>
  4.   <items>
  5.     <item_code/>
  6.   </items>
  7.   <order_number>
  8. </invoice_shipment>
  9.  
So I created a SQl query that uses FOR XML EXPLICIT:

Expand|Select|Wrap|Line Numbers
  1. SELECT     1 AS Tag, NULL AS Parent, 
  2. internal_id AS [invoice_shipment!1!internal_id!element], 
  3. ship_cost AS [invoice_shipment!1!shipping_cost!element], 
  4. NULL AS [items!2!order_Id],
  5. NULL AS [item!3!item_code!element], 
  6. order_number AS [order_number!4]
  7. FROM         [order]
  8.  
  9. UNION
  10. SELECT     2 AS Tag, 1 AS Parent, 
  11. internal_id AS [invoice_shipment!1!internal_id!element], 
  12. ship_cost AS [invoice_shipment!1!shipping_cost!element], 
  13. items.order_Id AS [items!2!order_Id], 
  14. NULL AS [item!3!item_code!element], 
  15. order_number AS [order_number!4]
  16. FROM         [order] INNER JOIN
  17.                       items ON [order].internal_id = items.order_Id
  18. UNION ALL
  19. SELECT     3 AS Tag, 2 AS Parent, 
  20. internal_id AS [invoice_shipment!1!internal_id!element], 
  21. ship_cost AS [invoice_shipment!1!shipping_cost!element], 
  22. items.order_Id AS [items!2!order_Id], 
  23. item.code AS [item!3!item_code!element], 
  24. order_number AS [order_number!4]
  25. FROM         [order] 
  26. INNER JOIN
  27. items ON [order].internal_id = items.order_Id INNER JOIN
  28. item ON items.items_Id = item.items_Id
  29.  
  30. UNION ALL
  31. SELECT     4 AS Tag, 1 AS Parent, 
  32. internal_id AS [invoice_shipment!1!internal_id!element], 
  33. ship_cost AS [invoice_shipment!1!shipping_cost!element], 
  34. null AS [items!2!order_Id], 
  35. null AS [item!3!item_code!element], 
  36. order_number AS [order_number!4]
  37. FROM         [order]
  38.  
  39.  
  40. ORDER BY [invoice_shipment!1!internal_id!element], [items!2!order_Id], [item!3!item_code!element], [order_number!4] FOR XML EXPLICIT
  41.  
  42.  
And that returns this:
Expand|Select|Wrap|Line Numbers
  1. <invoice_shipment>
  2.   <internal_id>1445627</internal_id>
  3.   <shipping_cost>0</shipping_cost>
  4.   <order_number>10348</order_number>
  5.   <items order_Id="1445627">
  6.     <item>
  7.       <item_code>EGBBDG</item_code>
  8.     </item>
  9.   </items>
  10.   <order_number>10349</order_number>
  11. </invoice_shipment>
  12. <invoice_shipment>
  13.   <internal_id>1445628</internal_id>
  14.   <shipping_cost>2</shipping_cost>
  15.   <items order_Id="1445628">
  16.     <item>
  17.       <item_code>EGOBDG</item_code>
  18.     </item>
  19.   </items>
  20.   <order_number>10349</order_number>
  21. </invoice_shipment>
  22. <invoice_shipment>
  23.   <internal_id>1445629</internal_id>
  24.   <shipping_cost>10</shipping_cost>
  25.   <items order_Id="1445629">
  26.     <item>
  27.       <item_code>EGBBDG</item_code>
  28.     </item>
  29.   </items>
  30.   <order_number>10350</order_number>
  31. </invoice_shipment>
  32. <invoice_shipment>
  33.   <internal_id>1445630</internal_id>
  34.   <shipping_cost>0</shipping_cost>
  35.   <items order_Id="1445630">
  36.     <item>
  37.       <item_code>EGBBDG</item_code>
  38.     </item>
  39.   </items>
  40. </invoice_shipment>
  41.  
The first <invoice_shipme nt> item has 2 <order_number > and the last has none. Anybody see what Im doing wrong here or maybe know of another way of doing this?

Thanks
Chad
May 27 '09 #1
0 1463

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

Similar topics

2
15216
by: Ken Lindner | last post by:
I have a need to become familiar with SQL Server 2000 for work. Needless to say I am new to SQL Server any version, but not IT in general. My employer has provided me with the SQL Server 2000 Personal disk from the SQL Server 2000 Enterprise kit as this is reported here on the MSDN web site to be the version that is supported on Windows XP. In fact so many of you kind people confess to having succeeded in doing it. I have tried...
19
14829
by: Thue Tuxen Sørensen | last post by:
Hi everybody ! I´m maintaining a large intranet (approx 10000 concurrent users) running on one IIS box and one DB box with sqlserver 2000. Currently there is 2,5 GB Ram, 1 1400 mhz cpu and 2 scsi disks installed on the db box. Sqlserver is set to use max 1,4 GB RAM, and the sqlserver does not seem to be using it all.
8
3561
by: Harris Boyce | last post by:
Hello, I'm trying to use the FOR XML EXPLICIT clause with SQL Server to deserialize data from my database into a strongly-typed collection object that I will use throughout my application. I initially tested my design by building a collection in code and then serializing it to/from an XML file, which worked fine. However, I have hit a brick wall trying to restore the data from SQL Server. I originally had my collection and object
2
52093
by: maltchev | last post by:
i need to insert data from an xml file into sql server table. the xml file contains only one record. how to insert the data? how to map the names of the fields in the xml file and the table? thank you in advance.
9
647
by: Steve Buster | last post by:
All right, I have read every forum, newsgroup etc about this issue and no one seems to know how to fix it. I am getting a "Server Application Unavailable" exception running my .NET 1.1 application. I use W2K SP4 and have applied the hot Fix KB824146 and KB824105, both IE fixes. I don't have VS installed because this is a Quality Environment. I do have .NET SDK and .NET 1.1 Runtime installed. I can't change my APSNET user to run as...
6
3782
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory†exception. To get an idea what happens I traced some values using performance monitor and got the following values (for one day): \\FFDS24\ASP.NET Applications(_LM_W3SVC_1_Root_ATV2004)\Errors During Execution: 7 \\FFDS24\ASP.NET Apps v1.1.4322(_LM_W3SVC_1_Root_ATV2004)\Compilations
2
6944
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip
8
2797
by: rbg | last post by:
I did use query plans to find out more. ( Please see the thread BELOW) I have a question on this, if someone can help me with that it will be great. In my SQL query that selects data from table, I have a where clause which states : where PermitID like @WorkType order by WorkStart DESC
0
8203
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8368
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8512
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7203
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4094
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4206
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2630
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.