Query to enter serial number on following pattern of data..
Data Pattern
ALTER TABLE SomeTable ADD NewCol INTEGER NULL
GO
UPDATE SomeTable
SET NewCol =
(SELECT COUNT(*)
FROM SomeTable AS S
WHERE Column1=SomeTable .Column1
AND KeyCol<=SomeTable .KeyCol)
- Column1: A A A B B C C C
- NewCol : 1 2 3 1 2 1 2 3
- KeyCol : There shoud be a primary key col in the required table(SomeTable)
ALTER TABLE SomeTable ADD NewCol INTEGER NULL
GO
UPDATE SomeTable
SET NewCol =
(SELECT COUNT(*)
FROM SomeTable AS S
WHERE Column1=SomeTable .Column1
AND KeyCol<=SomeTable .KeyCol)
Labels: Generate Serial number

