I have a table that contains nothing but dates for the next 20 years. I use this table as a quick lookup to determine certain information about a date in relation to my application – for example, if the date is a holiday, if the date has been flagged with a certain indicator, etc.
What I’m trying to do is pull the nth valid day from my table, starting at a specified date. Essentially, I just update a value with the returned value of a limited subquery. Here is my code so – I’m getting an error on the limit.
UPDATE _piece_detail
INNER JOIN mail_classes
ON mail_classes.class_id = _piece_detail.class_id
SET _piece_detail.est_delivery_date =
(SELECT date_value FROM date_lookup
WHERE date_value >= _piece_detail.date_prepared AND holiday != 1
LIMIT mail_classes.max_days,1)
WHERE est_delivery_date IS NULL;
I’ve tried casting mail_classes.max_days into an integer, but still no luck. I need this to be variable, since the number of days I need to count are based on the mail class.
I solved this by creating a function and using that with my routine. The function is as follows: