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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:25:01+00:00 2026-06-05T23:25:01+00:00

I’ve currently got a C# application that responds to HTTP requests. The body of

  • 0

I’ve currently got a C# application that responds to HTTP requests. The body of the HTTP request (XML) is passed to SQL Server, at which time the database engine performs the correct instruction. One of the instructions is used to load information about Invoices using the id of the customer(InvoiceLoad):

<InvoiceLoad ControlNumber="12345678901">
   <Invoice>
      <CustomerID>johndoe@gmail.com</CustomerID>
   </Invoice>
</InvoiceLoad>  

I need to perform a SELECT operation against the invoice table (which contains the associated email address).

I’ve tried using:

SELECT 'Date', 'Status', 'Location' 
FROM Invoices 
WHERE Email_Address = Invoice.A.value(.)  

using an xml.nodes('InvoiceLoad/Invoice/CustomerId') Invoice(A)

command.

However, as this query may run THOUSANDS of times per minute, I want to make it as fast as possible. I’m hearing that one way to do this may be to use CROSS APPLY (which I have never used). Is that the solution? If not, how exactly would I go about making this query as fast as possible? Any and all suggestions are greatly appreciated!

  • 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-05T23:25:04+00:00Added an answer on June 5, 2026 at 11:25 pm

    I don’t see why you would need a call to .nodes() at all – from what I understand, each XML fragment has just a single entry – right?

    So given this XML:

    <InvoiceLoad ControlNumber="12345678901">
       <Invoice>
          <CustomerID>johndoe@gmail.com</CustomerID>
       </Invoice>
    </InvoiceLoad>  
    

    you can use this SQL to get the value of the <CustomerID> node:

    DECLARE @xmlvar XML
    
    SET @xmlvar = '<InvoiceLoad ControlNumber="12345678901">
       <Invoice>
          <CustomerID>johndoe@gmail.com</CustomerID>
       </Invoice>
    </InvoiceLoad>'
    
    SELECT 
       @xmlvar.value('(/InvoiceLoad/Invoice/CustomerID)[1]', 'varchar(100)') 
    

    and you can join this against your customer table or whatever you need to do.

    If you have the XML stored in a table, and you always need to extract that value from <CustomerID>, you could also think about creating a computed, persisted column on that table that would extract that e-mail address into a separate column, which you could then use for easy joining. This requires a little bit of work – a stored function taking the XML as input – but it’s really quite a nice way to “surface” certain important snippets of data from your XML.

    Step 1: create your function

    CREATE FUNCTION dbo.ExtractCustomer (@input XML)
    RETURNS VARCHAR(255)
    WITH SCHEMABINDING
    AS BEGIN
        DECLARE @Result VARCHAR(255)
    
        SELECT 
            @Result = @Input.value('(/InvoiceLoad/Invoice/CustomerID)[1]', 'varchar(255)') 
    
        RETURN @result
    END
    

    So given your XML, you get the one <CustomerID> node and extract its “inner text” and return it as a VARCHAR(255).

    Step 2: add a computed, persisted column to your table

    ALTER TABLE dbo.YourTableWithTheXML
    ADD CustomerID AS dbo.ExtractCustomer(YourXmlColumnHere) PERSISTED
    

    Now, your table that has the XML column has a new column – CustomerID – which will automagically contain the contents of the <CustomerID> as a VARCHAR(255). The value is persisted, i.e. as long as the XML doesn’t change, it doesn’t have to be re-computed. You can use that column like any other on your table, and you can even index it to speed up any joins on it!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words

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.