Forums

This topic is locked

Sql Question

Posted 16 Aug 2001 01:10:39
1
has voted
16 Aug 2001 01:10:39 Suat donangil posted:
How can i filter the records of a database on a page that gives the results of last month records(or last week or last 3 days) with sql.

Replies

Replied 16 Aug 2001 04:12:41
16 Aug 2001 04:12:41 Owen Eastwick replied:
<font face='Arial'> Is this any help?

To return all the values in the Previous whole Month to the Current Month

For example if it is August this will display everything for July

SELECT *
FROM Orders
WHERE (((DatePart("m",[OrderDate]))=Month(Now())-1))


To return the Last Months Values - if the Table does not contain date values that are in the future you can omit <b>AND (Orders.OrderDate) &lt; Now()</b>

For example if the current date is 16/08/2001 this will show everything from 17/07/2001 to 16/08/2001

SELECT *
FROM Orders
WHERE (Orders.OrderDate) &gt; DateAdd("m",-1,Now()) AND (Orders.OrderDate) &lt; Now()


To return the Last Weeks Values - if the Table does not contain date values that are in the future you can omit <b>AND (Orders.OrderDate) &lt; Now()</b>

SELECT *
FROM Orders
WHERE (Orders.OrderDate) &gt; DateAdd("ww",-1,Now()) AND (Orders.OrderDate) &lt; Now()


To return the Last 3 Days Values - if the Table does not contain date values that are in the future once again you can omit <b>AND (Orders.OrderDate) &lt; Now()</b>

SELECT *
FROM Orders
WHERE (Orders.OrderDate) &gt; DateAdd("d",-3,Now()) AND (Orders.OrderDate) &lt; Now()


Regards


Owen
</font id='Arial'>

Replied 16 Aug 2001 04:25:11
16 Aug 2001 04:25:11 Suat donangil replied:
Thanks Owen. Verrry helpful.

Reply to this topic