title: query for first and last day of month
body: <p>If I have the name of the month, how can I have the first and last day of that month in SQL?</p>
  
  <p>I have this query to returns the month names:</p>
  
  <pre><code>DECLARE @StartDate  DATETIME,
          @EndDate    DATETIME;
  
  SELECT   @StartDate = '20110501'        
          ,@EndDate   = '20110801';
  
  
  SELECT  DATENAME(MONTH, DATEADD(MONTH, x.number, @StartDate)) AS MonthName
  FROM    master.dbo.spt_values x
  WHERE   x.type = 'P'        
  AND     x.number &lt;= DATEDIFF(MONTH, @StartDate, @EndDate)
  </code></pre>
  
  <p>Result:</p>
  
  <p><img src="https://i.stack.imgur.com/pye1k.png" alt="results"></p>
  
  <p>Now, how can i get the first and last day of that months? changing the query.</p>