From: Ian on
trying to write a query to select occupdate for one year prior to toustartdate

where occupdate < (toustartdate - 365)
where occupdate < (toustartdate - 1 year)
don't work

I'm sure it's a simple solution - can someone help me out.


From: Erland Sommarskog on
Ian (Ian(a)discussions.microsoft.com) writes:
> trying to write a query to select occupdate for one year prior to
> toustartdate
>
> where occupdate < (toustartdate - 365)
> where occupdate < (toustartdate - 1 year)
> don't work

These WHERE clauses would return rows where occupdate is one or more before
toustartdate, which does not really match your description. I would expect

WHERE occupdate >= dateadd(YEAR, -1, toustartdate)

But I suspect that there are a few more details I need to know to be able
to give you a really useful answer.


--
Erland Sommarskog, SQL Server MVP, esquel(a)sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx