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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:09:09+00:00 2026-06-05T01:09:09+00:00

Introduction I’m trying to query an xml column in SQL server 2008, but I

  • 0

Introduction

I’m trying to query an xml column in SQL server 2008, but I get an error I can’t fix.

This is the schema I use:

CREATE XML SCHEMA COLLECTION PublicationSchema AS '
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           elementFormDefault="qualified">
   <xs:import namespace="http://www.w3.org/XML/1998/namespace"
              schemaLocation="xml.xsd"/>
   <xs:element name="publication">
      <xs:complexType>
         <xs:sequence>
            <xs:element ref="metadata"/>
         </xs:sequence>
      </xs:complexType>
   </xs:element>
   <xs:element name="meta">
      <xs:complexType>
         <xs:attributeGroup ref="attlist-meta"/>
      </xs:complexType>
   </xs:element>
   <xs:attributeGroup name="attlist-meta">
      <xs:attribute name="name" use="required"/>
      <xs:attribute name="content"/>
      <xs:attribute name="scheme"/>
   </xs:attributeGroup>
   <xs:element name="metadata">
      <xs:complexType>
         <xs:sequence>
            <xs:element maxOccurs="unbounded" ref="meta"/>
         </xs:sequence>
      </xs:complexType>
   </xs:element>
   </xs:schema>'
GO

I create table with an XML column using the schema:
create table test (content XML(PublicationSchema))

I insert some data:

insert into test values(N'<?xml version="1.0" encoding="UTF-16"?>
<publication>
    <metadata>
        <meta name="type" content="plan" scheme="city"/>
        <meta name="statistics" content="second" scheme="informationtype"/>
    </metadata>
</publication>')

Problem

When i execute a query:

select * from test
where Content.exist('/publication/metadata/meta[@name] = "type"') = 1

I get this error:

 Msg 2213, Level 16, State 1, Line 3
 XQuery [test.content.exist()]: Cannot atomize/apply data()
    on expression that contains type 'meta' within inferred
    type 'element(meta,#anonymous) *'

Question

Doesn anyone know what I can do to fix this query?

  • 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-05T01:09:10+00:00Added an answer on June 5, 2026 at 1:09 am

    You have a syntax error in your exist function. You need to have the comparison between the brackets.

    select * 
    from test
    where Content.exist('/publication/metadata/meta[@name = "type"]') = 1
    

    This will work just fine with the XML you have if it was not for your schema. Applying that schema will give the error you referred to in a comment because you have no data type for the attribute name.
    You have two options to fix this. Alter the schema to include data types or rewrite the query above tricking SQL Server to treat the attribute as not part of schema.

    Specifying a data type for name would look like this.

    <xs:attributeGroup name="attlist-meta">
       <xs:attribute name="name" use="required" type="xs:string"/>
       <xs:attribute name="content"/>
       <xs:attribute name="scheme"/>
    </xs:attributeGroup>
    

    If you can not modify the schema you can use this query instead.

    select *
    from test
    where Content.query('/publication/metadata/meta').exist('/*[@name = "type"]') = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Introduction: I asked this question on the P2-forum already but I couldnt get any
Introduction: I'm trying to get additional fields to log with log4j, and its working
Introduction: So, I have an interview tomorrow and I'm trying to review SQL and
Introduction I can't seem to get the the ChartObjects.CopyPicture method to work in Excel
Google App Engine introduction specify this Your application can run in one of three
Introduction: Now I know this question could be very broad and it would be
Introduction: I want to loop through XML files with flexible categories structure. Problem: I
Introduction After watching this video from LIDNUG, about .NET code protection http://secureteam.net/lidnug_recording/Untitled.swf (especially from
Introduction I have a ListView and want to format only the second column. The
Introduction Let's say I have three Domain Objects: Proposition Phase Task A Proposition can

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.