SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to insert Parent node text if child node exist
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

shakerramasani
Starting Member

India
2 Posts

Posted - 09/10/2013 :  04:52:38  Show Profile  Reply with Quote
Here is a question on XQuerying in SQL (SQL Server 2008).
I have an XML that I need to output somewhat differently, for reference:


<?xml version="1.0"encoding="UTF-8"standalone="true"?>
<Computer >
<OS Name="Microsoft Windows 7 Ultimate"
ServicePack="1"/>OS - Category, Namem, Service Pack - Property,
<HardDisks>
<HardDisk Value="C:\ (NTFS)"/>
</HardDisks>
<LocalGroups>
<Group Name="Administrators">
<Member Name="Administrator"/>
<Member Name="whargrove"/>
</Group>
<Group Name="Backup Operators">
</Group>
<Group Name="Guests">
<Member Name="Guest"/>
</Group>
<Group Name="IIS_IUSRS">
<Member Name="IUSR"/>
</Group>
<Group Name="boinc_projects">
</Group>
</LocalGroups>
</Computer>

Need to insert data like below into my table from above xml.
Here is a one special case i.e If the node contains child node need to insert parent node as parent in the table Parent column if child not exist need to insert NULL.


Category Property Value Parent
OS Name WH& NULL
HardDisks Null Null Null
HardDisk Value C:\ (NTFS) HardDisks
LocalGroups Null Null Null
Group Name Administrators LocalGroups
Member Aministrator Null LocalGroups
Member whargrove Null LocalGroups



How could i achieve this?

Edited by - shakerramasani on 09/10/2013 05:36:56

James K
Flowing Fount of Yak Knowledge

3706 Posts

Posted - 09/10/2013 :  09:21:25  Show Profile  Reply with Quote
quote:
Originally posted by shakerramasani

Here is a question on XQuerying in SQL (SQL Server 2008).
I have an XML that I need to output somewhat differently, for reference:


<?xml version="1.0"encoding="UTF-8"standalone="true"?>
<Computer >
<OS Name="Microsoft Windows 7 Ultimate"
ServicePack="1"/>OS - Category, Namem, Service Pack - Property,
<HardDisks>
<HardDisk Value="C:\ (NTFS)"/>
</HardDisks>
<LocalGroups>
<Group Name="Administrators">
<Member Name="Administrator"/>
<Member Name="whargrove"/>
</Group>
<Group Name="Backup Operators">
</Group>
<Group Name="Guests">
<Member Name="Guest"/>
</Group>
<Group Name="IIS_IUSRS">
<Member Name="IUSR"/>
</Group>
<Group Name="boinc_projects">
</Group>
</LocalGroups>
</Computer>

Need to insert data like below into my table from above xml.
Here is a one special case i.e If the node contains child node need to insert parent node as parent in the table Parent column if child not exist need to insert NULL.


Category Property Value Parent
OS Name WH& NULL
HardDisks Null Null Null
HardDisk Value C:\ (NTFS) HardDisks
LocalGroups Null Null Null
Group Name Administrators LocalGroups
Member Aministrator Null LocalGroups
Member whargrove Null LocalGroups



How could i achieve this?


Your sample data is not valid/well-formed XML. If you post valid XML that would make it easier for someone who can answer the question.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000