Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query last year and beyond 1

Status
Not open for further replies.

stocktondesigns

Technical User
Aug 31, 2003
16
US
I have a press release section on our web site, I show current press as the current year. I would like to have a query that returns press releases older than 1 year, but am having difficulty creating the view in SQL.

I have created a similar query for the current year:

SELECT TOP 100 PERCENT *
FROM dbo.pressreleases
WHERE (DATEPART(yy, ReleaseDate) = DATEPART(yy, GETDATE()))

Would appreciate help on how to modify this, or prepare the SQL that would derive press releases older than 365 days.
 
Hi

SELECT TOP 100 PERCENT *
FROM dbo.pressreleases
WHERE Year(ReleaseDate) < Year(DateAdd("yyyy",-1,DATE()))

Not sure about the TOP 100 PERCENT bit, I assume you know what you are doing there

By the way your name "stocktondesigns" would that be Stockon On Tees in NE England?


Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
press releases older than 365 days
Why not simply replace this:
WHERE (DATEPART(yy, ReleaseDate) = DATEPART(yy, GETDATE()))
By this ?
WHERE ReleaseDate+365<Date()

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top