title: SQL Dynamic DatePart when using DateDiff
body: <p>Is there a way to pass the DatePart parameter of DateDiff as a variable?
  So that I can write code that is similar to this?</p>
  
  <pre><code>DECLARE @datePart VARCHAR(2)
  DECLARE @dateParameter INT
  
  SELECT @datePart = 'dd'
  SELECT @dateParameter = 28
  
  SELECT
      *
  FROM
      MyTable
  WHERE
      DATEDIFF(@datePart, MyTable.MyDate, GETDATE()) &lt; @dateParameter
  </code></pre>
  
  <p>The only ways I can think of doing it are with a CASE statement checking the value of the parameter or by building the SQL as a string and running it in an EXEC.</p>
  
  <p>Does anyone have any "better" suggestions? The platform is MS SQL Server 2005</p>