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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:24:28+00:00 2026-05-21T07:24:28+00:00

I am currently generating a Report using a Stored Procedure. The stored procedure gathers

  • 0

I am currently generating a Report using a Stored Procedure. The stored procedure gathers information about Unprocessed Files from a table of Files that resembles the following (simplfied for brevity):

Table Structure:

//File Table Fields
FILE_ID (int)
FILE_DATE (string)
FILE_CONTENTS (XML)
FILE_CONTENTS_STRING (string)
PROCESSED (bool)

Stored Procedure:

//Grabs the ID and Date for each of the Unprocessed Files
SELECT [FILE_ID],
       [FILE_DATE]
  FROM [tbFILES]
 WHERE [PROCESSED] = 0

I would like to output two additional fields that are found in the FILE_CONTENTS (or FILE_CONTENTS_STRING), which are both found in the XML / String in areas like these:

Portion of XML Structure:

    <FID.4>
      <FID.4.1>TESTING</FID.4.1>     //File Header
    </FID.4>
    <FID.5>
      <FID.5.1>TEST</FID.5.1>        //Owner Last Name
      <FID.5.2>TEST</FID.5.2>        //Owner First Name
      <FID.5.3 />
      <FID.5.4 />
      <FID.5.5 />
      <FID.5.6 />
      <FID.5.7 />
      <FID.5.8 />
    </FID.5>

What I would like to accomplish is to output these two values (File Header) and Owner Name (Last,First) as part of the Stored Procedure Call.

Output:

[FILE_ID]      //From Table
[FILE_DATE]    //From Table
[FILE_HEADER]  //From FILE_CONTENTS in <FID.4.1></FID.4.1>
[FILE_OWNER]   //From FILE_CONTENTS in <FID.5.1></FID.5.1>,<FID.5.2></FID.5.2>

Is it possibly to query this type of information from the XML File (FILE_CONTENTS) or the XML File in string-form (FILE_CONTENTS_STRING) using a SQL Stored Procedure?

Edit: First Attempt (unsuccessful)

SELECT FILE_ID,
       FILE_DATE,
       FILE_CONTENTS.value('(/PID.4/PID.4.1)[1]', 'varchar(16)') as FILE_HEADER,
       FILE_CONTENTS.value('(/PID.5/PID.5.1)[1]', 'varchar(16)') + ', ' +     
       FILE_CONTENTS.value('(/PID.5/PID.5.2)[1]', 'varchar(16)') as FILE_OWNER
  FROM [tbFILES]

which yielded NULL for the FILE_HEADER and FILE_OWNER fields. I presume that something more complex is required?

Update again: (Problem Solved!)

I had to add an additional section to the XML, as the portion provided was originally a snippet of a larger XML document.

  • 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-05-21T07:24:28+00:00Added an answer on May 21, 2026 at 7:24 am

    Try this query here – does that a) work and b) do what you’re looking for??

    -- test data setup
    DECLARE @test TABLE (FILE_ID INT, FILE_DATE DATETIME, FILE_CONTENTS XML)
    
    INSERT INTO @test VALUES(4711, '20110414', 
    '<FID.4>
          <FID.4.1>TESTING</FID.4.1>     //File Header
        </FID.4>
        <FID.5>
          <FID.5.1>TEST_LN</FID.5.1>        //Owner Last Name
          <FID.5.2>TEST_FN</FID.5.2>        //Owner First Name
          <FID.5.3 />
          <FID.5.4 />
        </FID.5>')
    
    -- select the values from the table and cross apply bits from the XML   
    SELECT 
         FILE_ID ,
         FILE_DATE ,
         Node.value('(/FID.4/FID.4.1/text())[1]', 'varchar(50)') AS 'File_Header',
         Node.value('(/FID.5/FID.5.1/text())[1]', 'varchar(50)') + ', ' +
         Node.value('(/FID.5/FID.5.2/text())[1]', 'varchar(50)') AS 'File_Owner'
    FROM
        @test
    CROSS APPLY
        FILE_CONTENTS.nodes('/*') AS Content(Node)
    

    My output looks like this:

    FILE_ID   FILE_DATE                File_Header   File_Owner
     4711     2011-04-14 00:00:00.000   TESTING      TEST_LN, TEST_FN
     4711     2011-04-14 00:00:00.000   TESTING      TEST_LN, TEST_FN
    

    If your XML had a proper root element, you could probably makes this even better (in terms of performance) – use the proper XPath in the CROSS APPLY condition to grab those bits of repeating nodes from the XML that you want.

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

Sidebar

Related Questions

we're currently generating all our official documents using XSL-FO transformation using .xml files as
I am currently using FO.net for generating my PDF report coming out of a
I'm currently generating SQL insert statements from more than one tables, and in the
We've currently got four web servers in a farm generating IIS web logs about
How can I go about generating a Friendly URL in C#? Currently I simple
my report is generating data that is supposed to be sorted by date and
I am currently generating a sitemap file dynamically using a HttpHandler, with a path
I'm currently generating a list using the jQuery tmpl plugin : <script id=mainTemplate type=text/x-jquery-tmpl>
We're currently generating reports for our web application using html5 / css3, and they
I'm generating a PDF using JasperReports from Java. I finally succeeded in making Jasper

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.