Hi, declare @tab1 table(VehicleID varchar(10),FirstOccur varchar(10))insert into @tab1 values ('AB1','1CC') insert into @tab1 values ('AB1','1AA') insert into @tab1 values ('AB1','1BB') insert into @tab1 values ('AB2','2DD') insert into @tab1 values ('AB2','2EE') insert into @tab1 values ('AB3','3FF') insert into @tab1 values ('AB3','3GG') insert into @tab1 values ('AB3','3HH') insert into @tab1 values ('AB3','3II') insert into @tab1 values ('AB4','4AA')
I need to create a complicated query (atleast for me) to generate the foll. output.--required output:VehicleID FirstOccur AddnlOccurAB1 1CC 1AA, 1BBAB2 2DD 2EEAB3 3FF 3GG, 3HHAB4 4AA
the column 'AddnlOccur' is a computed column...as shown above, firstoccur column will contain ONLY the first occurrence corresponding to each VehicleID.Next any occurrence will be added to the AddnlOccur column.Any pointers will be helpful.Thanks