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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:43:40+00:00 2026-05-20T06:43:40+00:00

I am trying to generate SELECT DISTINCT P.DOMAIN_ID, P.SOURCE_SYSTEM_ID FROM EDW.dbo.DOMAIN_VALUE AS P WHERE

  • 0

I am trying to generate

SELECT DISTINCT
        P.DOMAIN_ID,
        P.SOURCE_SYSTEM_ID
FROM    EDW.dbo.DOMAIN_VALUE AS P
WHERE   P.ID = 4
        AND CURRENT_FLAG = 'Y'
EXCEPT
( SELECT    F.DOMAIN_ID,
            F.SOURCE_SYSTEM_ID
  FROM      EDW.dbo.DOMAIN AS F
  WHERE     F.ID = 4
            AND F.CURRENT_FLAG = 'Y'
)
FOR     XML PATH('DOMAIN'),
            ROOT('DOMAIN_VALUE')  

The output value in XML in Result tab as

<REFERENCE_DOMAIN_VALUE>
   <REFERENCE_DOMAIN>
       <REFERENCE_DOMAIN_ID>10799</REFERENCE_DOMAIN_ID>
       <REFERENCE_SOURCE_SYSTEM_ID>7452-001</REFERENCE_SOURCE_SYSTEM_ID>
   </REFERENCE_DOMAIN>
</REFERENCE_DOMAIN_VALUE>

Now I need to convert this XML out to varchar(max) but the result needs to be same.

  • 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-20T06:43:41+00:00Added an answer on May 20, 2026 at 6:43 am

    Just subquery it into a scalar value and convert it. The trick here is that FOR XML in a subquery and EXCEPT on top don’t mix, so subquery the EXCEPT part first.

    SELECT CONVERT(varchar(max), (
        SELECT * FROM (
            SELECT DISTINCT P.DOMAIN_ID, P.SOURCE_SYSTEM_ID
            FROM EDW.dbo.DOMAIN_VALUE AS P
            WHERE P.ID = 4 AND CURRENT_FLAG = 'Y'
            EXCEPT (
            SELECT F.DOMAIN_ID, F.SOURCE_SYSTEM_ID
            FROM EDW.dbo.DOMAIN AS F
            WHERE F.ID = 4 AND F.CURRENT_FLAG = 'Y' )
        ) I
        FOR XML PATH('DOMAIN'), ROOT('DOMAIN_VALUE')
    ))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to generate an XML file using the data from a class,
I'm trying to generate this basic SQL statement using Query Expressions: SELECT * FROM
I'm trying to generate select names from a mysql database by using the rand()
I'm just trying to right click then select "Generate Model from database." and I
I'm trying to generate an XML output from SQL and need to use a
I am trying to generate a query that selects all from a user table
I trying to generate an XML document which is around 23 to 30 MB,
I'm trying to generate an HTML select element for filtering purposes on my CakePHP
I am trying to make a crosstab tables from the XML file from ToDoList
I'm trying to generate a Java Bean Skelleton from a WSDL (actually this will

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.