using xQuery with XML object in SQL 2005

Posted on 2009-02-23
Last Modified: 2013-11-11
I am trying to use xQuery in SQL 2005 to return the value of the InvoiceFlag field but I get a blank resultset instead of 1231.
can you tell me where the error is?


declare @xmlInputFields xml

set @xmlInputFields = '<Fields count="6">

  <Field name="ApllicationId" /> 

<!--  TemplateType is the prefix of the csv data file 


  <Field name="TemplateType" /> 

  <Field name="LetterId" /> 

  <Field name="UserID" /> 

  <Field name="SystemDate" /> 

  <Field name="InvoiceFlag">1231</Field> 


select  @xmlInputFields.query('

			for $i in /fields/field

			where $i/@name = "InvoiceFlag"

			return ($i/Field)') AS result

Open in new window

Question by:frankytee
    LVL 57

    Accepted Solution

    I believe it is expecting XML in another format. Check out the format in the links below:
    LVL 19

    Author Closing Comment

    sorry for the delay. we had to use openxml method as suggested in your links due to problems with xQuery with SQL.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
    So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now