sql - Find next certain weekday with mysql stored procedure -


in database have column 4 cases:

  • 1: tuesday
  • 2: wednesday
  • 3: thursday
  • 4: friday

im trying make stored procedure based on current date finds next weekday.
instance if wednesday xx.xx.xxxx , case 1, next tuesday yy.yy.yyyy upcoming week. here hard catch :) if wanted weekday next day, should select date of next week.

what have far:

begin select     case case_number     when 1 ''     when 2 ''     when 3 ''     when 4 ''     else 'unknown'     end customer customer_id = customerid; end 

im looking code between ' ' of course :) know need play date_add(curdate(), interval x day), (i think..) cant figure out! suggestion?

use dayofweek(now()) in fact naad case inside case.

depending on day of week number add appropriate amount of days now()

select     case case_number     when 1 case dayofweek(now())                  when 0 date_add(curdate(), interval x day)                  when 1 date_add(curdate(), interval x day)                  when 2 date_add(curdate(), interval x day)     .....                 end     when 2 ''     when 3 ''     when 4 ''     else 'unknown'     end customer 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -