Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Multiple Namespace query common elements


Multiple Namespace query common elements

Author
Message
LarrySql
LarrySql
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 116
Greetings all, this is my first post.
I've searched through the archives and haven't found quite what I'm looking for, so here goes.

I have two XML schemas which I've created and added into the same xml schema collection.
The two schemas are very similar apart from a few items, and share most of the other elements.
For external validation reasons, there must be two different schemas, and thus I have created two different namespaces rather than importing the first schema into the second.

Both schemas have an element named "DOCTYPE" which I'd like to query into a single column for display purposes, as these two schemas represent two different xml documents.

To simplify the problem, I have ns1 and ns2 in schema collection sc1.
The table created has 3 columns, msgId -varchar, InsertDate, and xmldoc - associated with sc1.
Both documents are inserted into the table and are correctly validated.

Here it what I have so far:


WITH XMLNAMESPACES (
   'http://a.b.com/schemas/type1' as ns1,
   'http://a.b.com/schemas/type2' as ns2,
   DEFAULT 'http://a.b.com/schemas/type1'
)
SELECT
msgId,
xmlDoc.value('(//DOCTYPE)[1]', 'nvarchar(max)') as DocType1,
xmlDoc.value('(//ns2BigGrinOCTYPE)[1]', 'nvarchar(max)') as DocType2,
FROM xmlDocuments



The output looks something like this:
msgId DocType1 DocType2
abc A {null}
cba {null} B


How can I rewrite this query to combine the output into a single column with output like this:
msgId DocType
abc A
cba B

Any advise would be greatly appreciated.
Thank you in advance!
Ninja's_RGR'us
Ninja's_RGR'us
SSC-Insane
SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)SSC-Insane (20K reputation)

Group: General Forum Members
Points: 20927 Visits: 9671
Look up coalesce and isnull in the books online (bol for short or sql server's help documentation).
LarrySql
LarrySql
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 116
Yup, that did it.
Did some reading here
In this case, I prefer coalesce as my plan is to expand the usefulness of this table to include multiple document types.

Thank you for your quick response !
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search