Reputation: 25
I have to update a column (called 'next-interaction
') in a table. The column contains date-time as values (ex: '2011-07-12 18:30:00'
). I have 160 records after applying all my where clauses.
Now, I have to make sets of 15 records and update their next-interaction
column with dates starting from '2014-01-06 16:00:00
' (excluding weekend dates).
In the sense,
first 15 records -> 2014-01-06 16:00:00 ( -> date-interaction column )
next 15 records -> 2014-01-07 16:00:00
next 15 records -> 2014-01-08 16:00:00
like wise, excluding saturdays and sundays dates to be incremented.
How can I do this? Can I do this with queries alone, or should i have to write a small php
-script for this?
Upvotes: 0
Views: 219
Reputation: 618
I would use a Cursor to solve the problem. A Cursor allows you to go through all the records of a table sequentially.
DECLARE cur1 CURSOR FOR SELECT next-interaction FROM your_table;
d = DATE_ADD(d ,INTERVAL 1 DAY)
and update the recordDAYOFWEEK(d) = 6 or DAYOFWEEK(d) = 7
you can check, if your date is a weekendIf you have to execute the code regularly I would recommend declaring a stored procedure (link)
I haven't tested this.
Upvotes: 1