Scooby08 Posted February 24, 2011 Share Posted February 24, 2011 Using MySQL.. Is there a way to make this UPDATE query work either by tweaking what's here or possibly another way? And I don't really want to add another column just to say it's been updated or not.. UPDATE table SET graded_on = IF(graded_on = '0000-00-00 00:00:00', NOW(), '0000-00-00 00:00:00') It seems I cannot use the 'graded_on' field within the graded_on if().. Not sure of another way to get it done.. As is, it updates any graded_on field that does NOT have a value of '0000-00-00 00:00:00'.. Strange that it's doing the opposite of what it should.. Thanks! Quote Link to comment Share on other sites More sharing options...
fenway Posted February 24, 2011 Share Posted February 24, 2011 Huh? Quote Link to comment Share on other sites More sharing options...
Scooby08 Posted February 24, 2011 Author Share Posted February 24, 2011 Well I did my best to explain.. It's pretty straight forward.. What I was trying to do was update the 'graded_on' field if the value was set to '0000-00-00 00:00:00', which is the default value for that field. Anyways, I did get it working with the following, but I read that it's not too efficient to run an IF statement within the WHERE clause.. Any thoughts? UPDATE table SET graded_on = NOW() WHERE event_status = 'Final' AND IF(graded_on = '0000-00-00 00:00:00', 1, 0) Thanks.. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 24, 2011 Share Posted February 24, 2011 Why not this? UPDATE table SET graded_on = NOW() WHERE event_status = 'Final' AND graded_on = '0000-00-00 00:00:00' Quote Link to comment Share on other sites More sharing options...
Scooby08 Posted February 24, 2011 Author Share Posted February 24, 2011 Wow did I really over think that one! Yeah that works perfectly obviously.. Thank you for taking my head out of the clouds jesirose!! Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 24, 2011 Share Posted February 24, 2011 Wow did I really over think that one! Yeah, ya did. :-P It happens. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.