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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:09:13+00:00 2026-06-13T04:09:13+00:00

I have a question. I know that has been asked before. I looked through

  • 0

I have a question. I know that has been asked before. I looked through the related questions but I could not get my SQL script to work.

Here is my query :

SELECT T1.PART_ID, T2.ID, T2.DESCRIPTION
FROM #TEMP T1 
INNER JOIN #TEMP2 T2 ON T1.PART_ID = T2.PART_ID
ORDER BY T2.ID

Table:

PART_ID |  ID        |    DESCRIPTION
----------------------------------
10002   |  1182505   |   Tagfahrlichtschaltung
80029   | 1182505    |   Bluetooth
20004   | 1212866    |    Kindersitzbefestigung
10045   |  1212866   |    Lederlenkradrriegelung
11908   |  1257946   |    Airbag
22346   | 1257946    |    Automatic

I want have the result like:

ID       | LISTOFPARTS
-----------------------------
1182505  |  "10002 : Tagfahrlichtschaltung ; 80029 : Bluetooth  "
1212866  |  "20004 : Kindersitzbefestigung ; 10045 : Lederlenkradrriegelung"
1257946  |  "11908 : AIRBAG ; 22346 : AUTOMATIC"

I guess it has to be something with XML PATH but I could not get it to work.
Could anyone rewrite the query so that it returns the results grouped and concatenated in string?

Solutions with or without XML PATH will be appreciated.

Thanks!

  • 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-06-13T04:09:15+00:00Added an answer on June 13, 2026 at 4:09 am

    This will work –

    DECLARE @TABLE TABLE (PART_ID INT,ID INT, DESCRIPTION VARCHAR(100))
    
    INSERT INTO @TABLE 
    VALUES
    (10002   ,1182505   ,   'Tagfahrlichtschaltung')
    ,(80029   , 1182505    ,   'Bluetooth')
    ,(20004   , 1212866    ,    'Kindersitzbefestigung')
    ,(10045   ,  1212866   ,    'Lederlenkradrriegelung')
    ,(11908   ,  1257946   ,    'Airbag')
    ,(22346   , 1257946    ,    'Automatic')
    
    ;WITH SUBQUERY
    AS
    (
        SELECT ID,(CAST(PART_ID AS VARCHAR(12)) + ' : ' + DESCRIPTION) 'CONCATED'
        FROM @TABLE 
    )
    
    SELECT ID, LEFT(pre_trimmed.CONCATED , LEN(pre_trimmed.CONCATED )-1) AS LISTOFPARTS
    FROM SUBQUERY AS extern
    CROSS APPLY
    (
        SELECT CONCATED + ','
        FROM SUBQUERY AS intern
        WHERE extern.ID = intern.ID
        FOR XML PATH('')
    ) pre_trimmed (CONCATED)
    GROUP BY ID, pre_trimmed.CONCATED
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that similar questions have been asked before, but I am very much
I know that the question has been asked before , but it's been two
I know this is a question that has been asked many times before, but
I know this question has been asked before but the solutions did not work
I know this has been asked before but I have looked at every answer
I know that maybe this question has been asked before, but I can't seem
I know this question has been asked before but I seem to have a
I know this question has been asked before, but I have tried the given
I know that this question has been asked before, but I'm looking for a
I know that this question has been asked previously, but before you give me

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.