Since you only have two columns, there is no good way to know what first name goes with what last name. I am assuming it is every 3 records makes 1 group. In order to do this I used a clustered update to create a groupID for every 3rd record.One this I joined the table to itself in order to get the results.Declare @MyTable table (ID int identity(1,1)Primary key clustered ,[type] varchar(30),[value] varchar(30), GroupID int)Insert into @MyTable(Type,Value)select 'FirstName' , 'Smith' Union allselect 'LastName' , 'John' Union allselect 'Company' , 'ABC Corp' Union allselect 'FirstName' , 'test' Union allselect 'LastName' , 'Johnson' Union allselect 'Company' , 'DBA Corp' Union allselect 'FirstName' , 'Jane' Union allselect 'LastName' , 'Doe' Union allselect 'Company' , 'DEF Inc' declare @MyCount int, @GroupID int,@Anchor intSelect @MyCount = 0,@GroupID = 0Update aset @Anchor = a.ID , @MyCount = case when @MyCount < 3 then @Mycount + 1 else 1 end, @GroupID = a.GroupID = case when @MyCount = 1 then @GroupID + 1 else @GroupID endfrom @MyTable aselect a.Value as FirstName,b.Value as LastName,c.Value as Companyfrom @MyTable aInner Join@MyTable bon a.GroupID = b.GroupIDInner Join@MyTable con b.GroupID = c.GroupIDwhere a.Type = 'Firstname'and b.Type = 'Lastname'and c.Type = 'Company'
Success is 10% Intelligence, 70% Determination, and 22% Stupidity.\_/ _/ _/\_/ _/\_/ _/ _/- 881