User Variable and DATE_ADD Function

User Variable and DATE_ADD Function

am 09.02.2007 17:28:33 von Peter Redding

Hi,

I have a query that uses a user variable to get the latest date from a
table using the MAX function. I then need to add 1 month onto this
date using DATE_ADD but the query just returns a NULL for the second
field.

Here's my query:

SELECT
CheckId,
#This displays correctly
@lastchecked:=MAX(CheckedDate),

#This just returns (NULL)
DATE_ADD(@lastchecked,INTERVAL 1 MONTH ) as lastcheckedplus1month
FROM
checkingtable
GROUP BY
CheckId

Has anyone managed to use DATE_ADD with a user variable? Can you tell
me if I'm missing something?

Any help is greatly appreciated.

Thank you,

Peter.