If table2
structure is fixed as you showed you can insert your expected result into it by a query like this:
INSERT INTO table2 (Manager, User1, User2, User3) SELECT Manager, MAX(CASE WHEN seq = 1 THEN [USER] END) AS User1, MAX(CASE WHEN seq = 2 THEN [USER] END) AS User2, MAX(CASE WHEN seq = 3 THEN [USER] END) AS User3 FROM ( SELECT *, ROW_NUMBER() OVER (PARTITION BY Manager ORDER BY [USER]) AS seq FROM table1) t GROUP BY Manager;
But, If table2
structure is not fixed you need to use Dynamic SQL.