i would like to know if someone have a function in SQL, than given a initial date and a day of week (tuesday for example) it can calculate when is the next date since de initial date that will be tuesday.
For example:
Given:
@initialdate=01-02-2013 --This day is Friday
@dayofweek = 3 --3 for Wednesday, 1 for Monday and 7 for Sunday
Return: date=06-02-2013
Maybe i have not explain well yet.. I mean A function that the parameter @dayofweek=3 (for wednesday) and then i can give many diferentes dates:
01-02-2013 then if @dayofweek=3 then next date will be 06-02-2013
02-02-2013 then if @dayofweek=3 then next date will be 06-02-2013
03-02-2013 then if @dayofweek=3 then next date will be 06-02-2013
04-02-2013 then if @dayofweek=3 then next date will be 06-02-2013
05-02-2013 then if @dayofweek=3 then next date will be 06-02-2013
06-02-2013 then if @dayofweek=3 then next date will be 13-02-2013
07-02-2013 then if @dayofweek=3 then next date will be 13-02-2013