Re: XMLQuery equivalent of SELECT [columnnameA] WHERE [columnnameB] IN

Tech-Archive recommends: Fix windows errors by optimizing your registry



If I understand your request correctly, you have a multi-valued column
(using the XML data type) and you have a multi-value parameter as
input. If that's the case then you'll need the nodes and value method
of the XML type to shred the input parameter into a relation, and then
again the nodes and value method along with CROSS APPLY to make a
relation out of the multi-value column.

I have a demonstration on my community site (http://www.ifoundtime.com/
community ) that illustrates this very requirement. It walks through
a table of people and their favourite colours, stored as an xml
column. It then takes an input parameter (in this case declared
simply as a variable of type XML with set to a literal value) and
queries for people who have a favourite colour in the list of
favourite colours. The sample queries are supplied there. Just look
for XmlCrossApply in the list of SQL Server videos.


Hope that helps,
Ralph Shillington
http://www.ifoundtime.com/community

On Apr 11, 10:20 pm, etech <e...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
I am new to XMLQuery, and review of the best practices and examples has yet
to yield an example of what I am trying to do:

Given a table containing an untyped XML column in which multiple nodes could
exist:

<ThingTypes><value id="8" /><value id="17" /><value id="22" /></ThingTypes>

And a multi-valued XML parameter passed in to a stored procedure,

<ThingTypes><value id="8" /><value id="17" /></ThingTypes>

How does one construct a query to:

"Return rows in table A in which ONE OR MORE node values in the input
parameter are found in the xml column of Table A"

This is sort of like the SQL query:

SELECT [columnA] FROM TableA
WHERE
TableA.[columnB] IN
SELECT ([columnC] FROM TableB WHERE [criteria])

Is there a method to do an "exist()" on an xml field where multiple nodes
could exist?

Thanks.


.



Relevant Pages

  • Re: Complicated while loop for a simpleton
    ... but XML is returned from opening the url ... Are you saying that the code: ... - Then runs another SQL query based on the data on the XML file. ...
    (comp.lang.php)
  • Re: How do I create an XML page dynamically . . .
    ... In SQL you would write a normal parameterized SQL query inside a stored proc ... and use FOR XML to transform the data into XML. ... Best regards ... is get the XML page to retrieve the correct columns ...
    (microsoft.public.sqlserver.xml)
  • Re: Database access sucks!
    ... Because the original message from Section 8 said that he or she would run a ... SQL query AS XML. ... programmer helping programmers. ...
    (microsoft.public.dotnet.general)
  • Re: sql data via query in specific xml output
    ... "HelpWithSqlXMLOuput" wrote in message ... >I have the following select statment that gets me the ... Below is the sql query as ... You will need to use a "for xml explicit" query. ...
    (microsoft.public.sqlserver.xml)
  • Re: persisting a query with for xml auto
    ... As with any other SQL query this is designed to be called from elsewhere - ... Insead of the results being returned as a recordset ... they are returned as xml. ... > I'm just playing around with the 'for xml' clause, but I'm missing its ...
    (microsoft.public.sqlserver.programming)