Jump to content

UPDATE database based on different values


jarv

Recommended Posts

hi, the following SQL:

UPDATE `customer` SET `ServiceDate` = DATE_ADD('1900-01-01', INTERVAL 40812 DAY)

updates all records in my table at the column ServiceDate with a date 40812 days after 1900-01-01

 

My problem is is that each of the values in the ServiceDate column are not 40812, they are all different. 40812, 40965, 40723 and so on...

 

Please help

Link to comment
Share on other sites

Hi

 

How do you know which number of days to add to which row?

 

I would guess that you have them stored on a different table. If so you probably want to do a JOIN within the UPDATE statement.

 

Something like:-

 

UPDATE FROM customer AS c 
LEFT JOIN someOtherTable as s 
ON c.blah = s.blah
SET c.ServiceDate` = DATE_ADD('1900-01-01', INTERVAL s.SomeDayCount DAY) 

 

All the best

 

Keith

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.