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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:44:38+00:00 2026-05-19T04:44:38+00:00

I have the following table structure ZoneID int ZoneName varchar(50) I need to get

  • 0

I have the following table structure

ZoneID int
ZoneName varchar(50)

I need to get this into an XML structure as follows to import into another system

    <Batch>
        <Record>
            <Insert>
                <Field>
                    <FieldName>ZoneID</FieldName>
                    <FieldValue>1</FieldValue>
                </Field>
                <Field>
                    <FieldName>ZoneName</FieldName>
                    <FieldValue>Interior</FieldValue>
                </Field>
            </Insert>
        </Record>
        <Record>
            <Insert>
                <Field>
                    <FieldName>ZoneID</FieldName>
                    <FieldValue>2</FieldValue>
                </Field>
                <Field>
                    <FieldName>ZoneName</FieldName>
                    <FieldValue>Exterior</FieldValue>
                </Field>
            </Insert>
        </Record>           
    </Batch>

So far I have this:

SELECT 
(            
    (SELECT     
    'ZoneID' as 'FieldName',
    [ZoneID] as 'FieldValue'
    FROM [dbo].[Condition_t_Zones]
    WHERE ZoneID = [Condition_t_Zones].ZoneID
    FOR XML PATH('field'), TYPE)

) as 'Insert'

FROM [Condition_t_Zones]

FOR XML PATH('record'), ROOT('batch')

But am unable to work out how to select the other field ‘ZoneName’ using another subquery.

Any help greatly appreciated.

  • 1 1 Answer
  • 3 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-19T04:44:38+00:00Added an answer on May 19, 2026 at 4:44 am

    Managed to get it working, think from my previous tests I had commas and Parentheses in the wrong places.

    Solution I arrived at as follows:

    SELECT 
    (
        (SELECT     
        'ZoneID' as 'FieldName',
        ZoneID as 'FieldValue'
        FROM [dbo].[Condition_t_Zones]
        WHERE ZoneID = [Condition_t_Zones].ZoneID
        FOR XML PATH('field'), TYPE) 
    ) as 'insert',
    (            
        (SELECT     
        'ZoneName' as 'FieldName',
        ZoneName as 'FieldValue'
        FROM [dbo].[Condition_t_Zones]
        WHERE ZoneID = [Condition_t_Zones].ZoneID
        FOR XML PATH('field'), TYPE)        
    ) 
    as 'insert'     
    FROM [Condition_t_Zones]
    
    FOR XML PATH('record'), ROOT('batch')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following table structure: EVENT_ID(INT) EVENT_NAME(VARCHAR) EVENT_DATE(DATETIME) EVENT_OWNER(INT) I need to add
I have a table structure like the following: table a: id int name varchar
I have following table structure: CREATE TABLE pilot_groups ( id INT PK, name VARCHAR(50),
I have the following table structure, which is imported into an Entity Framework project:
I have the following table structure in my database: create table Encargado( ID int
I have the following table structure: CREATE TABLE [Report].[MesReport]( [MesReportID] [int] IDENTITY(1,1) NOT NULL,
I have the following table structure as follows: (please ignore the blackbox. was formatting
I have the following table structure and I want a turn the query into
I have the following table: Videos ID(Int) Industries(Varchar) 11 3,5,8 22 5 33 1,3
I have the following table structure term_id int(11) concept_id int(11) idf double And I

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.