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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:18:43+00:00 2026-05-27T04:18:43+00:00

I have a employee table and the sample data in it is like this.

  • 0

I have a employee table and the sample data in it is like this. I am using sql server 2008.

CREATE TABLE employee (name nvarchar(255))

insert into employee (name) values ('Alex,AlexMartin'),
                            ('John,John'),
                            ('Mayr,Mayr'),
                            ('Shel,Sheila'),
                            ('corolla,corolla,corolla3'),
                            ('Mary4,Mary,Mary'),
                            ('Justin,Justin,Justin'),
                            ('Sara,Sara,Sara,Sara'),
                            ('clarence,clarence,clarence458,clarence,clarence'),
                            ('fiesta,fiesta,fiesta,fiesta,fiesta'),
                            ('scorpio1,scorpio,scorpio,scorpio4,scorpio')

I want to delete a value if all the values in the string are same example: John,John should be replaced by ‘John’. If all the names in string are not equal like Shel,Sheila it should retain both the values.
For this I am using

update employee set name=(select PARSENAME(REPLACE(name, ',', '.'), 2)) where (select PARSENAME(REPLACE(name, ',', '.'), 2))
like (select PARSENAME(REPLACE(name, ',', '.'), 1))
but it is changing Mary4,Mary,Mary to Mary. I tried combinations for 5, 4, and 3 names but there is no use. In fact for five names this code is not at all working. Is there any efficient way to do this?

  • 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-27T04:18:44+00:00Added an answer on May 27, 2026 at 4:18 am

    This will get the data in the format you’re looking for:

    CREATE TABLE #Employee (Name NVarChar(255));
    INSERT INTO #Employee (Name) VALUES ('Alex,AlexMartin'),
                                ('John,John'),
                                ('Mayr,Mayr'),
                                ('Shel,Sheila'),
                                ('corolla,corolla,corolla3'),
                                ('Mary4,Mary,Mary'),
                                ('Justin,Justin,Justin'),
                                ('Sara,Sara,Sara,Sara'),
                                ('clarence,clarence,clarence458,clarence,clarence'),
                                ('fiesta,fiesta,fiesta,fiesta,fiesta'),
                                ('scorpio1,scorpio,scorpio,scorpio4,scorpio'),
                                ('Another');
    
    SELECT Name, CASE
     WHEN CHARINDEX(Name, ',') = 0 THEN Name
     WHEN
      REPLACE(REPLACE(Name, LEFT(Name, CHARINDEX(',', Name) - 1), ''), ',', '') = ''
        THEN LEFT(Name, CHARINDEX(',', Name) - 1)
      ELSE Name
     END Result
    FROM #Employee;
    
    DROP TABLE #Employee;
    

    It works by getting the first name in the comma-separated list. By your requirements all of the items have to be identical in order to condense the list, so it doesn’t matter which element in the list we use for comparison.

    All occurrences of the first item are removed from the list. Then all of the commas are removed. If the resulting value is empty (i.e. '') then we know all of the items are identical. In that case the first element is used as the Result value. Otherwise, we return the original list unchanged.

    EDIT: Some of your data mustn’t have a , in it, so I’ve updated the answer to take care of that. It will just return the same input if a delimiter doesn’t exist.

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

Sidebar

Related Questions

I have very simple data model like this: create table Company ( id int
sql server 2005 : i have a column empid in employee table with identity
I have a table called Employee with the following fields: EmpID Salary Name I
I have a table which has employee relationship defined within itself. i.e. EmpID Name
I'm new to PostgreSQL. I have tables like: CREATE TABLE Person ( ID SERIAL
I have an employee table that displays the employee number, name, and manager's employee
We have a simple table with employee data containing a 100k records. We want
Suppose I have employee and department table, employee has foreign key departmentID that is
I have a table: Employee (employeeID) EmployeeRank (rankID, employeeID) Now I have another table
i have a procedure in which i am inserting record in employee table.nad getting

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.