title: best way to "glue" columns together
body: <p>I need to combine columns from about 15 tables in one large table. Something the following works. But it takes very long to run while the CPU usage spikes to 100%, which causes concerns. Any suggestions will be highly appreciated.</p>
  
  <pre><code>declare @t1 table (empid int)
  declare @t2 table (empid int, phone varchar(50))
  declare @t3 table (empid int, license varchar(50))
  declare @t4 table (empid int, email varchar(100))
  
  insert into @t1 values (1)
  insert into @t1 values (2)
  insert into @t1 values (3)
  insert into @t2 values (1, '5551234')
  insert into @t2 values (2, '5553333')
  insert into @t2 values (2, 'ttt2222')
  insert into @t3 values (2, 'L4455')
  insert into @t3 values (3, 'L7890')
  insert into @t4 values (2, 'xxx@abc')
  
  SELECT t1.empid, t2.phone, t3.license, t4.email
  FROM
      @t1 t1
      LEFT OUTER JOIN
      (SELECT empid, phone, row_number() over (partition by empid order by phone) as rn 
      FROM @t2) t2 
      ON t2.empid = t1.empid
      FULL OUTER JOIN
      (SELECT empid, license, row_number() over (partition by empid order by license) as rn 
      FROM @t3) t3 
      ON t3.empid=t1.empid and (t2.rn is null or t3.rn = t2.rn)
      FULL OUTER JOIN
      (SELECT empid, email, row_number() over (partition by empid order by email) as rn 
      FROM @t4) t4
      ON t4.empid=t1.empid and t4.rn=coalesce(t2.rn, t3.rn) --image how long this coalesce clause is going to be for the 15th table?
  order by t1.empid, t2.rn
  </code></pre>