Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8028917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:16:32+00:00 2026-06-05T00:16:32+00:00

Consider the following XML file: <?xml version=1.0 encoding=ISO-8859-1?> <Input Control=1234567890> <Patient> <AccountID>johnsmith@gmail.com</AccountID> <Name> <Title>Mr</Title>

  • 0

Consider the following XML file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<Input Control="1234567890">
   <Patient>
      <AccountID>johnsmith@gmail.com</AccountID>
      <Name>
         <Title>Mr</Title>
         <First>John</First>
         <Middle>J</Middle>
         <Last>Smith</Last>
      </Name>
      <Addresses>
         <Address Type="Billing">
            <Line1>123 Main St</Line1>
            <Line2>Unit #1</Line2>
            <City>Anytown</City>
            <State>MD</State>
            <PostalCode>78470</PostalCode>
            <Country>USA</Country>
            <Zone>TR89</Zone>
         <Address Type="Contact">
            <Line1>55 Main St</Line1>
            <City>Anytown</City>
            <State>MD</State>
            <PostalCode>78470</PostalCode>
            <Country>USA</Country>
            <Zone>TR89</Zone>
         </Address>
      </Addresses>
      <Phones>
         <Phone Type="Daytime">555-221-2525</Phone>
         <Phone Type="Evening">555-355-1010</Phone>
      </Phones>
      <Selects>
         <Select Name="Current">0</Select>
      </Selects>
   </Patient>
</Input>  

I need to ‘shred’ the XML (using XPath/XQuery) into the following table:

  Account    Nam_Pr   Nam_Fst  Nam_Lst  Adrs1Main  Adrs2Main  CityMain ... 
     1        Mr.      John     Smith  123 Main St  Unit #1    Anytown

The issue is, that I need to populate the AdrsMain fields with the data from the Address Type=”Billing element only if it’s present in the file. Otherwise, the AdrsMain fields are populated from the Address Type=”Contact” element. How can I accomplish this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T00:16:36+00:00Added an answer on June 5, 2026 at 12:16 am

    Turns out it was a little bit harder than I imagined, so I’ll go ahead and answer this message. I don’t recall xquery from attributes requiring me to do any conversions to null because (I thought) the values returned were already null. Because of this, you might need to convert some empty strings back to null. Luckily, I found about a cool little operator called nullif.

    But here’s the idea.

    create table docs ( id int primary key, xmlbit xml);
    

    assume your document files are added
    and then you can do

    with things (BillingLine1,ContactLine1)  as
    (
    SELECT 
    nullif(cast(xmlbit.query('data(/Input/Patient/Addresses/Address[@Type="Billing"]/Line1)') as varchar(100)),'') as BillingLine1,
    nullif(cast(xmlbit.query('data(/Input/Patient/Addresses/Address[@Type="Contact"]/Line1)') as varchar(100)),'') as ContactLine1
    from docs  
     )
    select BillingLine1, ContactLine1, Coalesce(BillingLine1,  ContactLine1) as needed from things;
    

    Demo: http://sqlfiddle.com/#!3/b3fbd/15

    There are probably other ways you could do this. I have a feeling if you really wanted to, you could do everything within the xquery/xpath statements, and it may even be more advantageous, but I’m not sure.

    Edit: Please do note the size of the varchars I’ve cast them to; you may need to adjust to see fit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following XML: <?xml version=1.0 encoding=ISO-8859-1?> <catalog> <cd> <title>Empire Burlesque</title> <artist> <name>Bob</name> <surname>Dylan</surname>
Consider the following XML: <?xml version=1.0 encoding=ISO-8859-1?> <CATALOG> <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY>
consider my 'destinationURLLookUp.xml' file has the following structure <?xml version=1.0 encoding=UTF-8?> <destinationURLs xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance> <destinationURL
Consider the following XML: <?xml version="1.0" encoding="utf-8"?> <treelist id="foo" displayname="display"> <treelink id="link" /> </treelist>
Consider we have the following xml document <?xml version=1.0 encoding=utf-8?> <Root> <Child /> </Root>
Consider the following css and html. <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE html PUBLIC -//W3C//DTD XHTML
Consider the following XML: <?xml version=1.0 encoding=UTF-8?> <OS> <data> <OSes> <centos> <v_5> <i386> <id>centos5-32</id>
Let's consider the following XML Schema: <?xml version=1.0 encoding=UTF-8?> <schema targetNamespace=http://www.example.org/library elementFormDefault=qualified xmlns=http://www.w3.org/2001/XMLSchema xmlns:lib=http://www.example.org/library>
Consider the following radio button example. <?xml version=1.0 encoding=utf-8?> <mx:Application xmlns:mx=http://www.adobe.com/2006/mxml> <mx:Script> <![CDATA[ private
I have an XML file of the following structure: <?xml version=1.0 encoding=utf-8?> <root> <ArrayOfLocationDTO

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.