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 table containing cells with text of various lengths. It is essential
I have have some code which adds new cells to a table and fills
Imagine I have table like this: id:Product:shop_id 1:Basketball:41 2:Football:41 3:Rocket:45 4:Car:86 5:Plane:86 Now, this
i have to switch in between two table as per users choice i can
I have a table with each cell containing a label and a text field.
Question for YUI experts... I have a table and I've made each cell of
If you have a recursive structure, say, child tables located inside td cells of
I have table inside a div tab. The table has 40 rows in it
I have table with 50 entries (users with such details like Name Surname Location
I have table rows of data in html being filled from a CGI application.

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.