lulu50
asked on
update query
Hi,
I want to update the AdsStatus in the database based on the length of the stored AdsDate .
updated AdsStatus where AdsDate is between 30 days period.
Update ADS
set AdsStatus = 5
where AdsDate > (CURRENT_DATE()- 30) and
(MainCategory = 4 or MainCategory = 5 or MainCategory = 6)
I want to update the AdsStatus in the database based on the length of the stored AdsDate .
updated AdsStatus where AdsDate is between 30 days period.
Update ADS
set AdsStatus = 5
where AdsDate > (CURRENT_DATE()- 30) and
(MainCategory = 4 or MainCategory = 5 or MainCategory = 6)
ASKER
I want to calculate the date difference between
today's date and AdsDate (than say update the record when the difference is more than 30 days)
today's date and AdsDate (than say update the record when the difference is more than 30 days)
Update ADS
set AdsStatus = 5
where CURRENT_DATE()-AdsDate > 30 and (MainCategory = 4 or MainCategory = 5 or MainCategory = 6)
set AdsStatus = 5
where CURRENT_DATE()-AdsDate > 30 and (MainCategory = 4 or MainCategory = 5 or MainCategory = 6)
I would just replace CURRENT_DATE()-AdsDate with DATEDIFF(day,AdsDate,CURRE NT_DATE()) . SQL sometimes does weird things with direct date calculations.
Try this
Update ADS
set AdsStatus = 5
where datediff(day,AdsDate,getdate()) > 30 AND
(MainCategory = 4 or MainCategory = 5 or MainCategory = 6)
This will work for a difference of more than thirty days in either direction (before or after)
In Access:
Update ADS
set AdsStatus = 5
where (CURRENT_DATE()-AdsDate > 30 OR AdsDate - CURRENT_DATE() > 30) and (MainCategory = 4 or MainCategory = 5 or MainCategory = 6)
In Access:
Update ADS
set AdsStatus = 5
where (DATE()-AdsDate > 30 OR AdsDate - DATE() > 30) and (MainCategory = 4 or MainCategory = 5 or MainCategory = 6)
ASKER
Update ADS
set AdsStatus = 5
where datediff(day,AdsDate,getda te()) > 30 AND
(MainCategory = 4 or MainCategory = 5 or MainCategory = 6)
Error Executing Database Query.
Syntax error or access violation: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'getdate()) > 30 AND (MainCategory = 4 or MainCategory = 5 or MainCategory =' at line 3
set AdsStatus = 5
where datediff(day,AdsDate,getda
(MainCategory = 4 or MainCategory = 5 or MainCategory = 6)
Error Executing Database Query.
Syntax error or access violation: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'getdate()) > 30 AND (MainCategory = 4 or MainCategory = 5 or MainCategory =' at line 3
MySQL uses NOW() instead of GETDATE()
ASKER
Update ADS
set AdsStatus = 5
where datediff(day,AdsDate,NOW() ) > 30 AND
(MainCategory = 4 or MainCategory = 5 or MainCategory = 6)
Syntax error or access violation: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NOW()) > 30 AND (MainCategory = 4 or MainCategory = 5 or MainCategory = 6)' at line 3
set AdsStatus = 5
where datediff(day,AdsDate,NOW()
(MainCategory = 4 or MainCategory = 5 or MainCategory = 6)
Syntax error or access violation: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NOW()) > 30 AND (MainCategory = 4 or MainCategory = 5 or MainCategory = 6)' at line 3
MySQL datediff is also different. Try this:
Update ADS
set AdsStatus = 5
where datediff(AdsDate,NOW()) > 30 AND
(MainCategory = 4 or MainCategory = 5 or MainCategory = 6)
Update ADS
set AdsStatus = 5
where datediff(AdsDate,NOW()) > 30 AND
(MainCategory = 4 or MainCategory = 5 or MainCategory = 6)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you
Open in new window
For Access:
Open in new window