title: SQL Date range using dynamic params
body: <p>I have custom table, which stipulates in days how long to retain records for. I need to know how I can pass in a variable into a BETWEEN statement to returns only the records from today inclusive, -variable.</p>
  
  <pre><code>WHERE (MessageDate BETWEEN GETDATE() AND DATEADD(day, DATEDIFF(day, 0, GETDATE()), - 7))
  </code></pre>
  
  <p>-7 in this instance would be 7 days from today, and is meant to be a parameter which I pass in.</p>