title: How do I achieve transposing of rows into columns in MS SQL
body: <p>I have two tables:</p>
  
  <p>Departments --&lt; Employees</p>
  
  <p>Department table has data such as:</p>
  
  <pre><code>id, Name
  1, Marketing
  2, Sales
  </code></pre>
  
  <p>Employees table has data such as:</p>
  
  <pre><code>id, Name, DepartmentId, RatePerDay
  1, Alex,1, 40
  2, Bob,1, 30
  3, Calvin,1, 40
  4, Dal,1, 30
  </code></pre>
  
  <p>I want to get two data sets back as follows for each department:</p>
  
  <pre><code>DepartmentName, Employee1,Employee12,Employee13,Employee14
  Marketing, Alex, Bob, Calvin, Dal
  
  DepartmentName, RatePerDay1, RatePerDay2, RatePerDay3, RatePerDay4
  Marketing, 40,30,40,30
  </code></pre>
  
  <p>I have to write a MS SQL 2008 Stored procedure which achieves this result?</p>
  
  <p>Any help is appreciated </p>