weird WHILE statement behaviour
by Louis van Eijk, May 4, 2007 00:07 I was working on a FUNCTION that would give me the next date of a workingday. I couldn't find any standard functions for this in MySQL, so I wrote one myself.
The problem with the following code is that the WHILE statement doesn't read the result from the SQL command within the WHILE statement.
DEFAULT datum1 = $today$; SETOPTION DATE = 'dmy';SET workingdays = 'Monday Tuesday Wednesday Thursday Friday'; SET date2 = $dateAdd($date1$, 1 , 'yyyy-mm-dd');
SQL SELECT DAYNAME('$date2$') as weekday; %>First: $weekday$<%
SETOPTION DATE = 'ymd';
WHILE not $match($workingdays$,$weekday$); SET date2 = $dateAdd($date2$, 1 , 'yyyy-mm-dd'); SQL SELECT DAYNAME('$date2$') as weekday; ENDWHILE;
SQL SELECT DAYNAME('$date2$') as weekday; %> $date2$ $weekday$
In this example the "weekday" stays the same within the WHILE statement. But it should be set again by the SQL statement.
A workaround for this problem is to SET a new variable in the WHILE statement. So after the SQL command I use
SQL SELECT DAYNAME('$date2$') as tempday; SET weekday = $tempday$;So the question is why doesnt the WHILE statement read the new value set by the SQL statement.
gtx.
Louis
Name E-mail optional TopicMessage:
HTTP Link: Link text: