Question: I have an Update statement where it recognizes duplicate values in one field and for each one found I want to increment the time up by one minute in a date/time field. I can't change the duplicate value because it breaks other parts of the project.

My code is currently:

```
UPDATE table
SET Date = GETDATE()
Where Seq in (Select Seq from table 
Group By Seq
Having COUNT(Seq) > 1)

```

Currently it sets all the dates to the same time. How would I set the Date so that each gets a unique time?

I tried something like:

```
SET Date = DATEADD(Mi,1, Date)

```

This increments up by 1 minute on all records. How do I touch them all separately?

Answer: 
You can use `ROW_NUMBER` in a `CTE`:

```
WITH CTE AS(
    SELECT *,
        rn = ROW_NUMBER() OVER(ORDER BY(SELECT NULL))
    FROM Seq
    WHERE Seq IN(SELECT Seq FROM Seq GROUP BY Seq HAVING COUNT(Seq) > 1)
)
UPDATE CTE
    SET Date = DATEADD(MINUTE, rn, GETDATE())

```
Try this:

```
UPDATE table
SET Date = DATEADD(Mi,1, Date)
Where ROWID in (Select MIN(t.ROWID) from table t
Group By Seq
Having COUNT(Seq) > 1);

```