Tuesday, 25 October 2011

Query to enter serial number on following pattern of data..

Data Pattern

  • 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:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home