This topic is locked

Previous Month Query

8/1/2008 1:36:02 PM
PHPRunner General questions
J
jskewes author

Hello,

Can someone suggest a way to modify this query to display record from the previous month.

So; all of the previous month, but not the current month.

Thank you for the help.
/john
SELECT

`Index`,

SalesRep,

`New-Used`,

StockNum,

CONCAT(`Year`, ' ', Model) AS YrMod,

`Year`,

Make,

Model,

TradeIn,

ACV,

`FE-Gross`,

`BE-Gross`,

DelvDate,

RDR,

SoldDate,

`Comment`,

Delivered,

Customer,

`BDC-Lead`,

Split,

`Share`,

`Value`,

SplitFrontEnd

FROM `_log`

WHERE YEAR(SoldDate) = YEAR(CURDATE()) AND MONTH(SoldDate) = MONTH(CURDATE())

ORDER BY SoldDate DESC

T
thesofa 8/1/2008

Have you tried

WHERE YEAR(SoldDate) = YEAR(CURDATE()) AND MONTH(SoldDate) = (MONTH(CURDATE())-1)

?

J
jskewes author 8/1/2008

Hi-

Thanks.

I did try that and the result is the same.

???

Have you tried

WHERE YEAR(SoldDate) = YEAR(CURDATE()) AND MONTH(SoldDate) = (MONTH(CURDATE())-1)

?

T
thesofa 8/1/2008

Try

WHERE YEAR(SoldDate) = YEAR(CURDATE()) AND MONTH(SoldDate) = (MONTH(CURDATE()-1))

instead of

WHERE YEAR(SoldDate) = YEAR(CURDATE()) AND MONTH(SoldDate) = (MONTH(CURDATE())-1)

J
jskewes author 8/1/2008

Hi-

Again, thanks but no.

I get a syntax error.

funny I can't find anything on this.

Try

WHERE YEAR(SoldDate) = YEAR(CURDATE()) AND MONTH(SoldDate) = (MONTH(CURDATE()-1))

instead of

WHERE YEAR(SoldDate) = YEAR(CURDATE()) AND MONTH(SoldDate) = (MONTH(CURDATE())-1)

J
jskewes author 8/1/2008

Hi- got it!

WHERE YEAR(SoldDate) = YEAR(CURDATE()) AND MONTH(SoldDate) = MONTH(DATE_SUB(CURDATE(), INTERVAL 1 MONTH))
took a while but I friggin' figured it out.
DATE_SUB and DATE_ADD are pretty handy.
/john

Hi-

Again, thanks but no.

I get a syntax error.

funny I can't find anything on this.