XQuery - Only return if not null
- From: Mike Müller <spam_mike_mueller@xxxxxxxxxxx>
- Date: Tue, 3 Feb 2009 17:22:50 +0100
Hi there
I have the following (simplyfied) xml document, which is hold in one of my table columns:
<Root>
<ElementABC P1="07" P2="07"/>
<ElementDEF P1="09" P2="07" P4="43" />
<ElementGHI P1="01" P2="07" P8="43" />
</Root>
Now I want to transpose the value of the P1 parameter into a new column named ColumnA. This works fine with the following statement:
SELECT HhID, MetUNo, StartDate,
AttributeDataXml.value('(Root/ElementABC/@P1)[1]','varchar(200)') as ColumnA,
FROM tTestTable
The problem is that my XML document does sometimes contatin the ElementABC and sometimes the ElementDEF. So if the ElelmetABC is found, then i want to use it's P1 value for the ColumnA. If it is not there the i want to try if the ElementDEF is found and use it's value for ColumnA.
I need some kind if if then else or how do I get what I want? I tried:
SELECT HhID, MetUNo, StartDate,
AttributeDataXml.value('(Root/ElementABC/@P1 or Root/ElementDEF/@P1)[1]','varchar(200)') as ColumnA,
FROM tTestTable
But this does then result in the value of true/false :-)
Is there anyone how knows how to solve this? Any help would really be appreciated!
Thanks a lot!
.
- Follow-Ups:
- Re: XQuery - Only return if not null
- From: Martin Honnen
- Re: XQuery - Only return if not null
- Prev by Date: RE: How to Find Missing > in an XML Doc
- Next by Date: Re: XQuery - Only return if not null
- Previous by thread: How to Find Missing > in an XML Doc
- Next by thread: Re: XQuery - Only return if not null
- Index(es):
Relevant Pages
|