asked on
TreeCertificate
------------------
TreeCodeID CurrentStatusId
12345 LIVE
23241 REGISTERED
23423 LIVE
TreeCertificateHistory
-------------------------
TreeCodeId StatusID TreeHistDateAdded
12345 CODE_CREATED 14/06/2010
23241 REGISTERED 14/12/2010
23423 CODE_CREATED 19/04/2009
23333 CODE_CREATED 02/10/2009
SELECT TreeCertificate.TreeCodeID
FROM TreeCertificate, TreeCertificateHistory
WHERE CurrentStatusID = 'LIVE'
AND TreeCertificate.TreeCodeID = TreeCertificateHistory.TreeCodeID
AND TreeHistDateAdded < DATEADD(month, -25, GETDATE())
AND StatusID = 'CODE_CREATED'
AND TreeHistDateAdded < SELECT DATEADD(quarter,DATEDIFF(quarter,0,DATEADD(month,-1,GETDATE()))-8,0)
ASKER
Microsoft SQL Server 2005 is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning. It includes support for managing XML data and allows a database server to be exposed over web services using Tabular Data Stream (TDS) packets encapsulated within SOAP (protocol) requests.
TRUSTED BY
ASKER
Thanks for the reference
The correct datetime stored in the database is
>> 2009-08-12 14:52:56.002
Yes I have been trying to figure the correct syntax / logic to use in my SQL statement.
I am strill struggling a bit - please can you help?
thanks