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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:14:36+00:00 2026-05-28T04:14:36+00:00

If there is a table called employee EmpID EmpName ———- ————- 1 Mary 1

  • 0

If there is a table called employee

EmpID           EmpName
----------      -------------
1               Mary
1               John
1               Sam
2               Alaina
2               Edward

Result I need in this format:

EmpID           EmpName
----------      -------------
1               Mary, John, Sam
2               Alaina, Edward

Q: this record is in same Employee table. I have almost no experience using UDFs, stored procedures, I need to be done this thing through query.Is this possible without using UDFs, SP’s.

  • 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-28T04:14:37+00:00Added an answer on May 28, 2026 at 4:14 am
    1. FOR XML PATH trick and article
    2. CLR User defined aggregate
    3. for sql server prior version 2005 – temporary tables

    An example of #1

    DECLARE @t TABLE (EmpId INT, EmpName VARCHAR(100))
    INSERT @t VALUES
    (1, 'Mary'),(1, 'John'),(1, 'Sam'),(2, 'Alaina'),(2, 'Edward')
    SELECT distinct
        EmpId,
        (
            SELECT EmpName+','
            FROM @t t2
            WHERE t2.EmpId = t1.EmpId
            FOR XML PATH('')
        ) Concatenated
    FROM @t t1
    

    How to strip the final comma – is on your own

    A CLR aggregate c# code for #2

    using System;
    using System.Collections.Generic;
    using System.Data.SqlTypes;
    using System.Text;
    using Microsoft.SqlServer.Server;
    using System.IO;
    
    namespace DatabaseAssembly
    {
        [Serializable]
        [SqlUserDefinedAggregate(Format.UserDefined,
            IsInvariantToNulls = true,
            IsInvariantToDuplicates = true,
            IsInvariantToOrder = true,
            MaxByteSize = -1)]
        public struct StringJoin : IBinarySerialize
        {
            private Dictionary<string, string> AggregationList
            {
                get
                {
                    if (_list == null)
                        _list = new Dictionary<string, string>();
                    return _list;
                }
            }
            private Dictionary<string, string> _list;
    
            public void Init()
            {
    
            }
    
            public void Accumulate(SqlString Value)
            {
                if (!Value.IsNull)
                    AggregationList[Value.Value.ToLowerInvariant()] = Value.Value;
    
            }
    
            public void Merge(StringJoin Group)
            {
                foreach (var key in Group.AggregationList.Keys)
                    AggregationList[key] = Group.AggregationList[key];
            }
    
            public SqlChars Terminate()
            {
                var sb = new StringBuilder();
                foreach (var value in AggregationList.Values)
                    sb.Append(value);
                return new SqlChars(sb.ToString());
            }
    
            #region IBinarySerialize Members
    
            public void Read(System.IO.BinaryReader r)
            {
    
                try
                {
                    while (true)
                        AggregationList[r.ReadString()] = r.ReadString();
                }
                catch (EndOfStreamException)
                {
    
                }
            }
    
            public void Write(System.IO.BinaryWriter w)
            {
                foreach (var key in AggregationList.Keys)
                {
                    w.Write(key);
                    w.Write(AggregationList[key]);
                }
            }
    
            #endregion
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i need to do this : There is a table called table1 it has
i need to do this : There is a table called table1 it has
I have an order header table called OrderH. In this table there is a
I have a table called items. IN this table there are many columns. One
Suppose I have a table called Companies that has a DepartmentID column. There's also
There is a table in a databse, let's call this table Document. This table
Ok... I have a database table called employees.. This has columns called ID, Name,
Assuming that there's a table called tree_node , that has the primary key called
Say I have a table named EMPLOYEE, and the table has a field called
i have an table called employees empID name startdate Middate DEptID 1 kumar 2011-04-30

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.