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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:33:02+00:00 2026-06-09T16:33:02+00:00

I’ve been looking for a way to show one column in multiple rows, one

  • 0

I’ve been looking for a way to show one column in multiple rows, one cell. The content of it separated by comma’s.

For example, in stead of:

ProjectID  Name                 count
-------------------------------------
   2       Technical Services    31
   1       Security Services     32
   7       Technical Services    32

I would like the result of my query to look like this:

Name                 Label
---------------------------
Technical Services   31,2
Technical Services   32,7
Security Services    32,1 

I also want the result of my query to look like this: (like Group_Concate in MySQL)

Name                 Label
-------------------------------
Security Services    32,1 
Technical Services   31,2: 32,7
  • 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-09T16:33:04+00:00Added an answer on June 9, 2026 at 4:33 pm

    Try this:

    SELECT  Name, 
    CAST(count AS VARCHAR(10)) + ',' + CAST(ProjectID AS VARCHAR(10))
    AS Label FROM table1
    

    Result

    NAME                   LABEL
    ----------------------------
    Security Services      32,1
    Technical Services     32,7
    Technical Services     31,2
    

    See this SQLFiddle

    If you want to group by Name (Something like Group_Concate in MySQL) there is no any method for it in SQL Server. It’s just a logic behind it.
    So try this:

    SELECT  * FROM    (
        SELECT  DISTINCT Name
        FROM    table1
        ) table2
    CROSS APPLY
        (SELECT  CASE ROW_NUMBER() 
          OVER(ORDER BY ProjectId) 
          WHEN 1 THEN '' ELSE ': ' END + 
          (CAST(table3.count AS VARCHAR(10)) + ',' 
          + CAST(table3.ProjectID AS VARCHAR(10)) )
        FROM    table1 table3
        WHERE   table3.Name = table2.Name
        ORDER BY ProjectID
        FOR XML PATH ('')
        ) table3(Label)
    

    So the result will be

    NAME                  LABEL
    --------------------------------
    Security Services     32,1
    Technical Services    31,2: 32,7
    

    See this SQLFiddle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been looking for a way to call a class's constructor that is analogous
I've been looking for a way to hash a given string in C# that
I've been looking for a way to test to see if the user has
I've been looking at the way resiznig works in Cocoa Touch and it looks
I have been looking for a way to remove an attachment from Jira using
I've been looking for a way to set the driver preferences for chrome driver
I have been looking for a way to get rid of the nasty black
I have been looking for a way to allow users to manually override geolocation
Been looking around and can't find a definite way to do this... I need
I've been looking at a clean way of implementing shut down logic for a

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.