title: TSQL - list multiple records across multiple columns
body: <p>is there a way to list multiple records across multiple columns eg. 2 columns? There must be no link between the records that are present in the same row.</p>
  <p>current:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>id</th>
  <th>date</th>
  <th>hours</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>01/01/2022</td>
  <td>M</td>
  </tr>
  <tr>
  <td>2</td>
  <td>02/01/2022</td>
  <td>P</td>
  </tr>
  <tr>
  <td>3</td>
  <td>07/01/2022</td>
  <td>P</td>
  </tr>
  <tr>
  <td>7</td>
  <td>01/01/2022</td>
  <td>N</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>result:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>id</th>
  <th>date</th>
  <th>hours</th>
  <th>id</th>
  <th>date</th>
  <th>hours</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>01/01/2022</td>
  <td>M</td>
  <td>2</td>
  <td>02/01/2022</td>
  <td>P</td>
  </tr>
  <tr>
  <td>3</td>
  <td>07/01/2022</td>
  <td>P</td>
  <td>7</td>
  <td>01/01/2022</td>
  <td>N</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Thanks for your help</p>
  <hr />
  <p>i tried with 3 columns:</p>
  <pre><code>WITH cte AS (
      SELECT *, ROW_NUMBER() OVER (ORDER BY id) rn
      FROM yourTable
  )
  
  SELECT MAX(CASE WHEN rn % 3 = 2 THEN id END) AS id1,
         MAX(CASE WHEN rn % 3 = 2 THEN date END) AS date1,
         MAX(CASE WHEN rn % 3 = 2 THEN hours END) AS hours1,
  
         MAX(CASE WHEN rn % 3 = 1 THEN id END) AS id2,
         MAX(CASE WHEN rn % 3 = 1 THEN date END) AS date2,
         MAX(CASE WHEN rn % 3 = 1 THEN hours END) AS hours2
  
         MAX(CASE WHEN rn % 3 = 0 THEN id END) AS id3,
         MAX(CASE WHEN rn % 3 = 0 THEN date END) AS date3,
         MAX(CASE WHEN rn % 3 = 0 THEN hours END) AS hours3
  FROM cte
  GROUP BY (rn - 1) / 3;
  </code></pre>
  <p>but the result is not sorted by id.
  The result is not the following:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>id1</th>
  <th>date1</th>
  <th>hours1</th>
  <th>id2</th>
  <th>date2</th>
  <th>hours2</th>
  <th>id3</th>
  <th>date3</th>
  <th>hours3</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>01/01/2022</td>
  <td>M</td>
  <td>2</td>
  <td>02/01/2022</td>
  <td>P</td>
  <td>3</td>
  <td>07/01/2022</td>
  <td>P</td>
  </tr>
  <tr>
  <td>7</td>
  <td>01/01/2022</td>
  <td>N</td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  </tr>
  </tbody>
  </table>
  </div>