title: Can you pull from before a casted time
body: <p>sql newbie here. I'm trying to make a report for a tracking software where assets go into the database with a &quot;Status&quot; and a time stamp when they make that change.</p>
  <p>What I'm trying to do is write a report that tells me when something hits the status 'complete' but its origin status was a month prior. How would I go about getting this to work properly with declaring a start and end date?</p>
  <pre><code>Declare @StartDate datetime
  Declare @EndDate datetime
  
  -- Set the start and end dates here  yyyy-mm-dd --
  set @StartDate = '2021-08-01'
  set @EndDate = '2021-08-31'
   Select *
   from assetcurrent.dbo ac
   inner join (select assetid, min(hdate) as [hdate] from history where hstatus = &quot;created&quot; group by assetid, hdate) ah
  
  Where a.status in ('complete')
  and cast(ac.hdate as date) &lt;= cast(@EndDate as date)
      and cast(ac.hdate as date) &gt;= cast(@StartDate as date)
      and ah.hdate &lt; dateadd(month, -1, @StartDate)
      
  order by [Report number]
  </code></pre>
  <p>Am I properly using dateadd here in the where clauses? I just get 0 results when I know there should be at least a few.</p>
  <p>Thanks!</p>