Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Need to get just last 2 years worth of data

Author  Topic 

TRACEYSQL
Aged Yak Warrior

594 Posts

Posted - 2008-06-23 : 18:19:40
SELECT * FROM TEST NOLOCK
WHERE FY_CD = DATEPART(YEAR, GETDATE())

This gives me last years - but they want last years 2007 and 2008

Any suggestions

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-06-23 : 18:26:06
SELECT * FROM TEST NOLOCK
WHERE FY_CD >= DATEADD(year,DATEDIFF(year,0,GETDATE())-1,0)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-06-23 : 18:28:43
Wait. Are you stroring only year values in FY_CD column?

SELECT * FROM TEST NOLOCK
WHERE FY_CD >= DATEPART(year,DATEADD(year,-1,GETDATE()))



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

TRACEYSQL
Aged Yak Warrior

594 Posts

Posted - 2008-06-24 : 08:15:39
Yes only year in the fy_cd column..
I try it out
Thanks
Go to Top of Page
   

- Advertisement -