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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:13:59+00:00 2026-05-22T15:13:59+00:00

Sample Table: ID              Product 1              Survey 1              Policy 1              Invoice 2              Invoice 2              Survey 3              Policy 3              Invoice What I

  • 0

Sample Table:

ID             Product
1              Survey
1              Policy
1              Invoice
2              Invoice
2              Survey
3              Policy
3              Invoice

What I would like to end up with is a table w/ 3 rows (one for each of the ids) w/ the products in a comma separated list:

ID             Product
1              Survey, Policy, Invoice
2              Invoice, Survey
3              Policy, Invoice

I was able to do this w/ a User Defined Scalar Function, but it is very slow, I believe the more proper solution would to be a cursor, but that is where I need the help

  • 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-22T15:14:00+00:00Added an answer on May 22, 2026 at 3:14 pm

    Not sure about the speed vs UDF or cursor but you can give this a try:

    with T(ID, Product) as 
    (
    select 1,              'Survey' union all
    select 1,              'Policy' union all
    select 1,              'Invoice' union all
    select 2,              'Invoice' union all
    select 2,              'Survey' union all
    select 3,              'Policy' union all
    select 3,              'Invoice'
    )
    
    select
      T1.ID,
      stuff((select ', '+T2.Product
             from T as T2 
             where T1.ID = T2.ID
             for xml path(''), type).value('.', 'nvarchar(max)'), 1, 2, '') as Product
    from T as T1
    group by T1.ID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For my question lets consider the following sample table data: ProductID    ProductName    Price   Category 1                Apple                 5.00       Fruits
well i have this messages table with sample values like these: msg_id recipient_id read
I have a sample file like the following: CREATE GLOBAL TEMPORARY TABLE tt_temp_user_11 (
I would like to make all cells of an HTML table clickable--that is, the
My SAMPLE table has the following five columns: sample_id (PK) (NUMBER) sampled_on (DATE) received_on
How can I concatenate two char columns within a perform screen? example: table sample
I am inserting a group of strings into my table. This is a sample
Consider a simple table with an auto-increment column like this: CREATE TABLE foo (
I got some sample data in a Table Testing which consists of two fields:
I am learning cakePHP 1.26. I got some sample data in a Table Testing

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.