It looks like the problem is that the variable vMaxMod does not contain a valid date (in number form) if the QVD exists. Put a TRACE statement in your script like:
TRACE vMaxMod = $(vMaxMod);
before calling your SQL Select to verify that vMaxMod has a valid value. The TRACE statement displays in the reload progress screen and the document log. Alternatively, If you run the script in debug mode, you can check the actual SELECT statement being sent to the server.
Logic will get you from a to b. Imagination will take you everywhere. - A Einstein