I have this table below: CREATE TABLE dbo.Test( ID INT IDENTITY(1,1) NOT NULL, Type VARCHAR(50) NULL,);INSERT INTO dbo.Test(Type) VALUES('A');INSERT INTO dbo.Test(Type) VALUES('A');INSERT INTO dbo.Test(Type) VALUES('A');INSERT INTO dbo.Test(Type) VALUES('B');INSERT INTO dbo.Test(Type) VALUES('B');INSERT INTO dbo.Test(Type) VALUES('C');INSERT INTO dbo.Test(Type) VALUES('A');INSERT INTO dbo.Test(Type) VALUES('A');ID | Type 1 | A 2 | A 3 | A 4 | B 5 | B 6 | C 7 | A 8 | A and I want a result like this:ID | Type | Grp1 | A | 12 | A | 13 | A | 14 | B | 25 | B | 26 | C | 37 | A | 48 | A |4Basically, they are grouped by the 'Type', but the problem is, the same 'Type' can occur downstream, but would be in a different group('Grp') because it is not part of the consecutive grouping.