title: Join two tables returning all rows as single row from the second table
body: <p>I want to get data in a single row from two tables which have one to many relation.</p>
  
  <ol>
  <li>Primary table</li>
  <li>Secondary table</li>
  </ol>
  
  <p>I know that for each record of primary table secondary table can have maximum 10 rows. Here is structure of the table</p>
  
  <p><strong>Primary Table</strong></p>
  
  <pre><code> -------------------------------------------------
  | ImportRecordId   |       Summary                |
  --------------------------------------------------
  |        1         |       Imported Successfully  |
  |        2         |       Failed                 |
  |        3         |       Imported Successfully  |
   -------------------------------------------------
  </code></pre>
  
  <p><strong>Secondary table</strong></p>
  
  <pre><code> ------------------------------------------------------
  | ImportRecordId   |       CodeName   |  CodeValue     |
  -------------------------------------------------------
  |        1         |       ABC        |  123456A       | 
  |        1         |       DEF        |  8766339       |
  |        1         |       GHI        |  887790H       |
   ------------------------------------------------------
  </code></pre>
  
  <p>I want to write a query with inner join to get data from both table in a way that from secondary table each row should be treated as column instead showing as multiple row.
  I can hard code 20 columns names(as maximum 10 records can exist in secondary table and i want to display values of two columns in a single row) so if there are less than 10 records in the secondary table all other columns will be show as null. </p>
  
  <p><strong>Here is expected Output.</strong> You can see that for first record in primary table there was only three rows that's why two required columns from these three rows are converted into columns and for all others columns values are null.</p>
  
  <pre><code>-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  | ImportRecordId |        Summary        | CodeName1 |  CodeValue1 |  CodeName2 | CodeValue2 |  CodeName3 |  CodeValue3 |  CodeName4 |  CodeValue4|  CodeName5 |  CodeValue5|  CodeName6 |  CodeValue6|  CodeName7 |  CodeValue7 |  CodeName8 |  CodeValue8 | CodeName9 |  CodeValue9 | CodeName10 |  CodeValue10|
  ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  |        1       | Imported Successfully |    ABC    |    123456A  |    DEF    |    8766339  |     GHI    |  887790H    |    NULL    |    NULL    |    NULL     |    NULL    |    NULL    |    NULL   |    NULL    |    NULL     |    NULL     |    NULL    |    NULL   |    NULL     |    NULL    |    NULL     |
   ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  </code></pre>
  
  <p>Here is my simple SQL query which return all data from both tables but instead multiple rows from secondary table i want to get them in a single row like above result set. </p>
  
  <pre><code>Select p.ImportRecordId,p.Summary,s.*
  from [dbo].[primary_table] p
  inner join [dbo].[secondary_table] s on p.ImportRecordId = s.ImportRecordId
  </code></pre>