title: SQL Calculate Days between two dates in one table
body: <p>I have a table <code>dbo.Trans</code> which contains an id called <code>bd_id</code>(varchar) and <code>transfer_date</code>(Datetime), also an identifier <code>member_id</code> pk is <code>trns_id</code> and is sequential</p>
  
  <p>Duplicates of <code>bd_id</code> and <code>member_id</code> exist in the table.</p>
  
  <pre><code>transfer_date       |bd_id| member_id | trns_id
  2008-01-01 00:00:00 | 432 | 111       | 1  
  2008-01-03 00:00:00 | 123 | 111       | 2  
  2008-01-08 00:00:00 | 128 | 111       | 3  
  2008-02-04 00:00:00 | 123 | 432       | 4
  .......
  </code></pre>
  
  <p>For each member_id, I want to get the amount of days between dates and for each <code>bd_id</code></p>
  
  <p>E.G., member <code>111</code> used <code>432</code> from <code>2008-01-01</code> until <code>2008-02-01</code> so return should be <code>2</code><br>
  Then next would be <code>5</code></p>
  
  <p>I know the <code>DATEDIFF()</code> function exists but I am not sure how to get the difference when dates are in the same table.</p>
  
  <p>Any help appreciated.</p>