title: SQL-Server combing datepart with getdate and dateadd
body: <p>I'm working on making a Stored procedure in SQL-server 2008 r2. Already got the SELECT and all the things done, but having some problems combining my datepart with a Dateadd and getdate. The thing is I want to show it like this in the query.</p>
  
  <p><strong>2013-06 2013-07 2013-08</strong></p>
  
  <p>So I try to use this code but I keep getting invalid syntax...</p>
  
  <pre><code>and Datepart(yy, Column) = 2013
  </code></pre>
  
  <p>But I dont want it to be hardcoded, since the people using the system should just be able to print it each month. That was why I was thinking getdate-1</p>
  
  <pre><code>DATEPART(MM,DATEADD(MM,-1 GETDATE())
  </code></pre>
  
  <p>I want to combine the hardcode and change it into the lower one. The SELECT code looks like this at the moment.</p>
  
  <pre><code>INSERT INTO #EXCEL(COL1,COL2,COL3)
  SELECT SUM (AVERAGE) / COUNT DISTINCT(TABLE.COLUMN)
  FROM TABLE
  INNER JOIN TABLE1 ON TABLE2.COLUMN = BLA BLA 
  WHERE SOMETHING = X
  AND DATEPART(YY,COLUMNDATE) = 2013
  AND DATEPART(MM,COLUMNDATE) = 8
  </code></pre>
  
  <p>I want to use my getdate combined, but I keep getting syntax error. </p>