-1

I am busy creating a VB.Net Windows Application. I am using a microsoft sql server database with a table called skedulering. I am trying to update a column (i.e Groep) with unique values based on another column (i.e. Kode). This value takes the first three characters of the Kode value and adds a integer to it. I think what I mean is best explained with the following :

enter image description here

All the red bordered rows have the same Groep value. Can anyone please help me to create the sql statement?

Regards

Gideon
  • 313
  • 1
  • 2
  • 18

1 Answers1

1

use dense_rank() to generate a running no

UPDATE t
SET    Groep = left(Kode, 3) + convert(varchar(10), rn)
FROM
(
    SELECT Kode, Groep, rn = dense_rank() over (partition by left(Kode, 3) order by Kode)
    FROM   yourtable
) t
Squirrel
  • 23,507
  • 4
  • 34
  • 32