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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:02:48+00:00 2026-05-11T00:02:48+00:00

If I have a table where the cells in a column should not have

  • 0

If I have a table where the cells in a column should not have the same values, how do I check this and update? (I know I can set constraints in the settings, but I don’t want to do that.)

Say the column name is called unique hash name and contains

 Peter Peter Peter Dave Dave 

and so on. I want that to transform to:

 Peter Peter1 Peter2 Dave Dave1 

What is the T-SQL for SQL Server to do that?

Update: For clarity’s sake, let’s call the table ‘Persons’ and the cell I want unique ‘UniqueName’. Could you make it a SELECT-statement, so I can test the result before updating. And I am using SQL Server 2005 and above.

  • 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. 2026-05-11T00:02:49+00:00Added an answer on May 11, 2026 at 12:02 am

    EDIT: I’ve changed the query to use your field names and added a ‘select-only’ query for you to preview.

    This is actually pretty easy to do… just use ROW_NUMBER() with a PARTITION clause:

    UPDATE Persons SET UniqueName = temp.DeDupded FROM     (SELECT ID,         CASE WHEN ROW_NUMBER() OVER             (PARTITION BY UniqueName ORDER BY UniqueName) = 1 THEN UniqueName         ELSE UniqueName + CONVERT(VARCHAR, ROW_NUMBER()             OVER (PARTITION BY UniqueName ORDER BY UniqueName)-1) END AS DeDupded     FROM Persons) temp WHERE Persons.ID = temp.ID 

    If you want a ‘select-only’, then here you go:

    SELECT ID,     CASE WHEN ROW_NUMBER() OVER         (PARTITION BY UniqueName ORDER BY UniqueName) = 1 THEN UniqueName     ELSE UniqueName + CONVERT(VARCHAR, ROW_NUMBER()         OVER (PARTITION BY UniqueName ORDER BY UniqueName)-1) END AS DeDupded FROM Persons 

    EDIT Again: If you’re looking for a SQL Server 2000 Solution…

    CREATE TABLE #Persons ( ID INT IDENTITY(1, 1), UniqueName VARCHAR(100) )  INSERT INTO #Persons VALUES ('Bob') INSERT INTO #Persons VALUES ('Bob') INSERT INTO #Persons VALUES ('Bob') INSERT INTO #Persons VALUES ('John') INSERT INTO #Persons VALUES ('John')  SELECT     ID,     CASE WHEN Position = 0 THEN UniqueName         ELSE UniqueName + (CONVERT(VARCHAR, Position))     END AS UniqueName FROM     (SELECT         ID,         UniqueName,         (SELECT COUNT(*) FROM #Persons p2 WHERE             p1.UniqueName = p2.UniqueName AND p1.ID > p2.ID) AS Position     FROM         #Persons p1) _temp  DROP TABLE #Persons 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form with the fields inside table cells. On the last column
I have a table containing cells with phone numbers. How can I allow the
I have a Table View Controller with cells. I want to update the text
How do I style one column on my table to not have any borders?
I have a reference set of data in a column of cells (it could
I have a table with a column of bit values. I want to write
I have an app that does not assign unique IDs to table cells. Given
I have a table with three columns, and two cells contain select boxes with
I have two table cells, with dynamic content. Table cell one works fine, when
My table cells have a font-size of 9pt. Within these table cells there is

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.