开发者

MySQL IF THEN SET

I have a table with

*PwdSettings that has a value of -50 (which is say 50 days)

*PwdDate (which is the date last updated)

*ExpDate (which is 0 or 1, if Password is old i need it set to 1)

I'm trying to write a query to say "IF PwdDate is < PwdSettings Then SET ExpDate = 1"

Here is what I have tried so far, everything throws an error.

UPDATE wp_users SET ExpDate = 1 WHEN PwdDate < DATE_ADD(CURDATE(), INTERVAL -50 DAY) WHERE user_email='dylan@wccit.com'

UPDATE wp_users SET Ex开发者_如何学运维pDate = 1 WHERE user_email='dylan@wccit.com' IF(PwdDate < DATE_ADD(CURDATE(), INTERVAL -50 DAY))

IF PwdDate < DATE_ADD(CURDATE(), INTERVAL -50 DAY) WHERE user_email='dylan@wccit.com' THEN SET ExpDate = 1


Use:

UPDATE wp_users 
   SET ExpDate = 1 
 WHERE PwdDate < DATE_ADD(CURDATE(), INTERVAL -50 DAY) 

...or, using DATE_SUB:

UPDATE wp_users 
   SET ExpDate = 1 
 WHERE PwdDate < DATE_SUB(CURDATE(), INTERVAL 50 DAY) 


Here is how i did it.

UPDATE wp_users 
SET ExpDate = IF(PwdDate <= DATE_ADD(CURDATE(), INTERVAL PwdSettings DAY), 1, 0)
WHERE user_email='myEmail@domain.com'


Put the extra condition in the WHERE clause:

UPDATE wp_users
SET ExpDate = 1
WHERE user_email='dylan@wccit.com'
AND PwdDate < CURDATE() - INTERVAL 50 DAY
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜