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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql query (last x days)

Status
Not open for further replies.

Grudge

Programmer
Jul 30, 2002
23
0
0
ZA
It's easy doing a query to get the last x records from the data (they each have a date field)

QUERY : select * from sourcetable order by date limit x

But I need to get the records that were added the last x days ??
 
select *
from sourcetable
where datediff(dd,<date field>,getdate()) >= 8
order by date RT
 
I am sorry. By mistake, I wrote 8 instead of @x

select *
from sourcetable
where datediff(dd,<date field>,getdate()) >= @x
order by date
RT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top