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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:13:25+00:00 2026-05-27T13:13:25+00:00

Not able to to get the desired XML output The following: SELECT 1 as

  • 0

Not able to to get the desired XML output

The following:

  SELECT  1 as Tag,
          0 as Parent,
          sID       as [Document!1!sID], 
          docID     as [Document!1!docID],
          null      as [To!2!value]
  FROM docSVsys with (nolock)
  where docSVsys.sID = '57'
  UNION ALL 
  SELECT 2 as Tag,
         1 as Parent,
         sID,
         NULL,
         value         
  FROM   docMVtext
  WHERE  docMVtext.sID = '57'
  ORDER BY [Document!1!sID],[To!2!value]
  FOR XML EXPLICIT;

Produces:

    <Document sID="57" docID="3.818919.C41P3UKK00BRICLAY0AR1ET2EBPYSU4SA">
      <To value="Frank Ermis" />
      <To value="Keith Holst" />
      <To value="Mike Grigsby" />
    </Document>

What I want is:

    <Document sID="57">
      <docID>3.818919.C41P3UKK00BRICLAY0AR1ET2EBPYSU4SA</docID>
      <To>
        <Value>Frank Ermis</Value>
        <Value>Keith Holst</Value>
        <Value>Mike Grigsby</Value>
      </To>
    </Document>

Can I get that ouput with FOR XML?

Ok I get they may be technically equivalent.
What I want and what I need are not the same.

Using xDocument for this is is SLOW.
There are millions of documents and need to XML up to 1 million at a time to XML.
The TSQL FOR XML is super fast.
I just need to get FOR XML to format.

The solution (based on accepted answer):

   SELECT top 4
     [sv].[sID] AS '@sID'
    ,[sv].[sParID] AS '@sParID' 
    ,[sv].[docID] AS 'docID'
    ,[sv].addDate as 'addDate'
    ,(SELECT [value] AS 'value'
       FROM  [docMVtext] as [mv]
       WHERE [mv].[sID] = [sv].[sID]
         AND [mv].[fieldID] = '113'
       ORDER BY [mv].[value]
       FOR XML PATH (''), type
     ) AS "To"  
    ,(SELECT [value] AS 'value'
       FROM  [docMVtext] as [mv]
       WHERE [mv].[sID] = [sv].[sID]
         AND [mv].[fieldID] = '130'
       ORDER BY [mv].[value]
       FOR XML PATH (''), type
     ) AS "MVtest" 
  FROM  [docSVsys] as [sv]
  WHERE [sv].[sID] >= '57' 
  ORDER BY 
      [sv].[sParID], [sv].[sID]
  FOR XML PATH('Document'), root('Documents')

Produces:

<Documents>
  <Document sID="57" sParID="57">
    <docID>3.818919.C41P3UKK00BRICLAY0AR1ET2EBPYSU4SA</docID>
    <addDate>2011-10-28T12:26:00</addDate>
    <To>
      <value>Frank Ermis</value>
      <value>Keith Holst</value>
      <value>Mike Grigsby</value>
    </To>
    <MVtest>
      <value>MV test 01</value>
      <value>MV test 02</value>
      <value>MV test 03</value>
      <value>MV test 04</value>
    </MVtest>
  </Document>
  <Document sID="58" sParID="57">
    <docID>3.818919.C41P3UKK00BRICLAY0AR1ET2EBPYSU4SA.1</docID>
    <addDate>2011-10-28T12:26:00</addDate>
  </Document>
  <Document sID="59" sParID="59">
    <docID>3.818920.KJKP5LYKTNIODOEI4JDOKJ2BXJI5P0BIA</docID>
    <addDate>2011-10-28T12:26:00</addDate>
    <To>
      <value>Vladimir Gorny</value>
    </To>
  </Document>
  <Document sID="60" sParID="59">
    <docID>3.818920.KJKP5LYKTNIODOEI4JDOKJ2BXJI5P0BIA.1</docID>
    <addDate>2011-10-28T12:26:00</addDate>
  </Document>
</Documents>

Now what I need to do is to add a DispName attribute to the element MVtext. Attribute cannot have any spaces and I would like to include the friendly name e.g. Multi Value Text.

  • 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-27T13:13:26+00:00Added an answer on May 27, 2026 at 1:13 pm

    Try something like this (untested, since I don’t have your database tables to test against…):

      SELECT 
         sv.sID AS '@sID',
         sv.docID AS 'docID',
         (SELECT 
             value AS 'value'
          FROM   
             dbo.docMVtext mv
          WHERE
             mv.sID = sv.sID
          ORDER BY mv.value
          FOR XML PATH (''), TYPE) AS 'To'    
      FROM   
          dbo.docSVsys sv
      WHERE  
          sv.sID = '57'
      ORDER BY 
          sv.sID
      FOR XML PATH('Document')
    

    Does that give you what you’re looking for?? And don’t you agree with John and me: this is much simpler than FOR XML EXPLICIT…..

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

Sidebar

Related Questions

not able to get this, can someone help for this LINQ query? select col1,
I am not able to get the hg head or status for a given
I'm not able to get this persistence file correct... I do not find any
I am not able to get my jwysiwyg and Jhtmlarea text editors to work
i tried to search this but was not able to get any proper help.I
This seems like a repeated question but i'm not able to get my answer.
I've read the DateFormatting guide and I'm still not able to get a working
I have few Question for which I am not able to get a proper
I know this is simple but I am not able to get it right
I want to position two ImageViews horizontally, but I am not able to get

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.