Re: Querying xml data with SQL
- From: "Denis Ruckebusch [MSFT]" <denisruc@xxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 15 Jan 2007 11:58:33 -0800
There is a query() method available for the xml datatype also.
Here is an example that queries all the <child> elements under <parent>
SELECT xmlcol.query('//parent/child') FROM MY_XML_TABLE
Here is a query that selects only the <child> nodes with values "A" or "B"
SELECT xmlcol.query('//parent/child[./text()="A" or ./text()="B"]') FROM
MY_XML_TABLE
I hope this helps you get started. Don't hesitate to come back to the newsgroup
if you have more questions.
Denis Ruckebusch
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"Cathy" <cathywigzell@xxxxxxxxxxx> wrote in message
news:1168858991.999652.272750@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I have a table in Microsoft SQL Server 2005 with column of datatype
xml. The xml may contain multiple elements of the same type, e.g.
multiple <child> elements for a single <parent>. How can I query on the
<child> elements?
For example, what would be the correct syntax for this query where both
parent and child are elements within the xml...
SELECT parent FROM MY_XML_TABLE WHERE child='A' OR child='B'
I've already had a play around with xml.value and xml.nodes - but I
think I'm missing something crucial!
Many thanks for your help,
Cathy
.
- Follow-Ups:
- Re: Querying xml data with SQL
- From: Cathy
- Re: Querying xml data with SQL
- References:
- Querying xml data with SQL
- From: Cathy
- Querying xml data with SQL
- Prev by Date: SQLXML Import Schema - must complexTypes always create separate ta
- Next by Date: Re: schema collection problem?
- Previous by thread: Querying xml data with SQL
- Next by thread: Re: Querying xml data with SQL
- Index(es):
Relevant Pages
|
Loading