Use DATEDIFF to calculate the difference between two dates:
WHERE DATEDIFF(DAY, sql_date, dts_start_day_ref) % days_in_schedule + 1 =
I'm not clear if I've got the parentheses in the correct place because you
had one missing from the code you posted.
If you still can't get it to work, please post some code to reproduce the
problem, including DDL and sample data. Your code worked for me once I
replaced the missing bracket.
Please reply only to the newsgroup