title: SQL Server Pivot or Unpivot
body: <p>I have a table which basically needs to be transposed, and a new SUM column added to it (DaySum). The transposition won't include all the rows, but only the ones specified (from 17-01-02 to 17-01-08) as you can see below in the result table.</p>
  
  <p>I have been trying different variations of Pivot and Unpivot, but I get the columns and values mixed up.</p>
  
  <p>This is the table I'm trying to modify:</p>
  
  <pre><code>Date          User1   User2   User3
  ------------------------------------
  17-01-01        1        0       1
  Week1           0        1       0
  17-01-02        1        0       1
  17-01-03        1        0       1
  17-01-04        1        1       1
  17-01-05        1        0       0
  17-01-06        1        0       0
  17-01-07        1        0       0
  17-01-08        1        1       0
  Week2           3        0       2
  </code></pre>
  
  <p>The result should look like this:</p>
  
  <pre><code>Name    17-01-02  17-01-03  17-01-04  17-01-05  17-01-06  17-01-07  17-01-08  DaySum  Week2
  -------------------------------------------------------------------------------------------
  User1       1         1         1         1         1         1         1       7       3
  User2       0         0         1         0         0         0         1       2       0
  User3       1         1         1         0         0         0         0       3       2
  </code></pre>
  
  <p>I greatly appreciate your help, thank you in advance.</p>