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 9190407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:27:14+00:00 2026-06-17T20:27:14+00:00

I’ve got a table in a SQL Server 2008 database with an nvarchar(MAX) column

  • 0

I’ve got a table in a SQL Server 2008 database with an nvarchar(MAX) column containing XML data. The data represents search criteria. Here’s what the XML looks like for search criteria with one top-level “OR” group containing one single criterion and a nested two-criterion “AND” group.

<?xml version="1.0" encoding="utf-16"?>
<SearchCriterionGroupArgs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <SingleCriteria>
    <SearchCriterionSingleArgs>
      <Operator>Equals</Operator>
      <Value>test</Value>
      <FieldIDs>
        <int>1026</int>
        <int>478</int>
      </FieldIDs>
      <EntityID>92</EntityID>
    </SearchCriterionSingleArgs>
  </SingleCriteria>
  <GroupCriteria>
    <SearchCriterionGroupArgs>
      <SingleCriteria>
        <SearchCriterionSingleArgs>
          <Operator>GreaterThan</Operator>
          <Value>2010-01-23</Value>
          <FieldIDs>
            <int>1017</int>
          </FieldIDs>
          <EntityID>92</EntityID>
        </SearchCriterionSingleArgs>
        <SearchCriterionSingleArgs>
          <Operator>LessThan</Operator>
          <Value>2013-01-23</Value>
          <FieldIDs>
            <int>1018</int>
          </FieldIDs>
          <EntityID>92</EntityID>
        </SearchCriterionSingleArgs>
      </SingleCriteria>
      <GroupCriteria />
      <EntityID>92</EntityID>
      <LogicalOperator>AND</LogicalOperator>
    </SearchCriterionGroupArgs>
  </GroupCriteria>
  <EntityID>92</EntityID>
  <LogicalOperator>OR</LogicalOperator>
</SearchCriterionGroupArgs>

Given a an input set of FieldID values, I need to search the table to find if there are any records whose search criteria refer to one of those values (these are represented in the “int” nodes under the “FieldIDs” nodes.)

By running this query:

select CAST(OptionalConditions as xml).query('//FieldIDs')
from tblMyTable

I get the results:

<FieldIDs>
  <int>1026</int>
  <int>478</int>
</FieldIDs>
<FieldIDs>
  <int>1017</int>
</FieldIDs>
<FieldIDs>
  <int>1018</int>
</FieldIDs>

(currently there’s only one record in the table with xml data in it.)

But I’m just getting started with this stuff and I don’t know what the notation would be to check those lists for the existence of any of an arbitrary set of FieldIDs. I don’t need to retrieve any particular nodes, just true or false for whether the input field IDs are referenced anywhere in the search.

Thanks for your help!

Edit: using Ranon’s solution, I got it working using a query like this:

SELECT *
FROM myTable
WHERE CAST(OptionalConditions as xml).exist('//FieldIDs/int[.=(1019,111,1018)]') = 1
  • 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-17T20:27:15+00:00Added an answer on June 17, 2026 at 8:27 pm

    Fetch all FieldIDs and compare them with the set id IDs to check against. XQuery’s =-operator compares in a set-based semantics, so if one of the IDs on the left side equal on one the right, this expression will evaluate to true.

    //FieldIDs/int = (42, 478)
    

    As “478” is a FieldID, this query will return true. “42” is one not available.

    I’m not sure about whether you will be able to cast the result to some sql-server-boolean-type as I haven’t got one running, but you will easily be able to try out yourself.


    If you’re also interested in the nodes contained, you could use this query:

    //FieldIDs/int[. = (42,478)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i got an object with contents of html markup in it, for example: string
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I want to construct a data frame in an Rcpp function, but when I

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.