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

  • Home
  • SEARCH
  • 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 693507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:45:39+00:00 2026-05-14T02:45:39+00:00

I have this query: SELECT DISTINCT IM.EDIFICIOS_ID, TI.TITULAR FROM IMPORTACION IM INNER JOIN I_EDIFICIO

  • 0

I have this query:

SELECT DISTINCT IM.EDIFICIOS_ID, TI.TITULAR
FROM IMPORTACION IM
INNER JOIN I_EDIFICIO IE ON IM.IMPORTACION_ID=IE.IMPORTACION_ID
INNER JOIN I_EDIFICIO_TITULAR ET ON IM.IMPORTACION_ID=ET.IMPORTACION_ID AND IE.EDIFICIO_ID=ET.EDIFICIO_ID
INNER JOIN I_TITULAR TI ON IM.IMPORTACION_ID=TI.IMPORTACION_ID AND ET.TITULAR_ID=TI.TITULAR_ID
WHERE TI.TITULAR IS NOT NULL AND TI.TITULAR<>''
ORDER BY IM.EDIFICIOS_ID, TI.TITULAR;

that returns this result set:

EDIFICIOS_ID TITULAR
------------ ------------------
1911         Ana María García
1911         Anselmo Piedrahita
1911         Manuel López
2594         Carlos Pérez
2594         Felisa García
6865         Carlos Pérez
6865         Felisa García
8428         Carlos Pérez

I want to concatenate the values from TITULAR for each EDIFICIOS_ID, so I get this:

EDIFICIOS_ID TITULAR
------------ ------------------
1911         Ana María García; Anselmo Piedrahita; Manuel López
2594         Carlos Pérez; Felisa García
6865         Carlos Pérez; Felisa García
8428         Carlos Pérez

I’m trying to use the FOR XML PATH trick. I’ve used it in the past but, since I can’t really understand how it works, I can’t figure out how to apply it to this specific case. Can you provide me with some ideas?

  • 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-14T02:45:39+00:00Added an answer on May 14, 2026 at 2:45 am

    try something like this:

    DECLARE @TableA  table (EDIFICIOS_ID int, TITULAR nvarchar(500))
    INSERT INTO @TableA VALUES (1911 ,'Ana María García')
    INSERT INTO @TableA VALUES (1911 ,'Anselmo Piedrahita')
    INSERT INTO @TableA VALUES (1911 ,'Manuel López')
    INSERT INTO @TableA VALUES (2594 ,'Carlos Pérez')
    INSERT INTO @TableA VALUES (2594 ,'Felisa García')
    INSERT INTO @TableA VALUES (6865 ,'Carlos Pérez')
    INSERT INTO @TableA VALUES (6865 ,'Felisa García')
    INSERT INTO @TableA VALUES (8428 ,'Carlos Pérez')
    
    ;with ResutSet AS
    (
        SELECT EDIFICIOS_ID,TITULAR FROM @TableA
        --replace with your query here and don't use @TableA
        --  SELECT DISTINCT IM.EDIFICIOS_ID, TI.TITULAR
        --  FROM IMPORTACION IM
        --  INNER JOIN I_EDIFICIO IE ON IM.IMPORTACION_ID=IE.IMPORTACION_ID
        --  INNER JOIN I_EDIFICIO_TITULAR ET ON IM.IMPORTACION_ID=ET.IMPORTACION_ID AND IE.EDIFICIO_ID=ET.EDIFICIO_ID
        --  INNER JOIN I_TITULAR TI ON IM.IMPORTACION_ID=TI.IMPORTACION_ID AND ET.TITULAR_ID=TI.TITULAR_ID
        --  WHERE TI.TITULAR IS NOT NULL AND TI.TITULAR<>''
        --  ORDER BY IM.EDIFICIOS_ID, TI.TITULAR;
    )
    SELECT
        c1.EDIFICIOS_ID
            ,STUFF(
                     (SELECT
                          '; ' + TITULAR
                          FROM ResutSet  c2
                          WHERE c2.EDIFICIOS_ID=c1.EDIFICIOS_ID
                          ORDER BY c1.EDIFICIOS_ID, TITULAR
                          FOR XML PATH('') 
                     )
                     ,1,2, ''
                  ) AS CombinedValue
        FROM ResutSet c1
        GROUP BY c1.EDIFICIOS_ID
        ORDER BY c1.EDIFICIOS_ID
    

    OUTPUT:

    EDIFICIOS_ID CombinedValue
    ------------ ---------------------------------------------------
    1911         Ana María García; Anselmo Piedrahita; Manuel López
    2594         Carlos Pérez; Felisa García
    6865         Carlos Pérez; Felisa García
    8428         Carlos Pérez
    
    (4 row(s) affected)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query: SELECT page.id, revision.title, revision.number FROM page INNER JOIN revision ON
I have this query: SELECT * FROM sample INNER JOIN test ON sample.sample_number =
I have this query: select top(2) property_id_ref ,image_file ,property_name from property_master a inner join
I have this query: SELECT DISTINCT(b.friend_id) AS possible_id FROM friends_friends a JOIN friends_friends b
So I have this query: SELECT DISTINCT(b.friend_id) AS possible_id FROM friend_friends a JOIN friends_friends
Let say that we have the following query: SELECT DISTINCT COUNT(`users_id`) FROM `users_table`; this
I have this sql query: SELECT DISTINCT url FROM paragraphs WHERE MATCH (title) AGAINST('$query')
I have this query: SELECT DISTINCT id, label FROM bbproduct_cust WHERE CUSTNO IN (SELECT
I have this query SELECT distinct username, time FROM `sadaat`.`wp_loginlog` where username != 'admin'
I have this query: select distinct id,name from table1 For a given ID, the

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.