If this is a typo:51c12| 1/1/2006| p2| 051c12| 1/2/2006| p3| 2i.e. it should be: 51c12| 1/1/2006| p1| 051c12| 1/2/2006| p2| 2then this works:select t1.[cl num], t1.[cont date] p1date, t1.daycount p1count, t2.[cont date] p2date, t2.daycount p2count, t3.[cont date] p3date, t3.daycount p3count from #table t1 left join #table t2 on t1.[cl num] = t2.[cl num] and t2.code = 'p2' left join #table t3 on t1.[cl num] = t3.[cl num] and t3.code = 'p3'where t1.code = 'p1'
Is the set {'p1','p2','p3' ...} finite ?If you search here or in your favorite search engine for 'pivot SQL Server' or 'Cross Tab Sql Server' you should get plenty of links that go into more depth.;-]... Quack Waddle