If your sql is working like your requirements you didn't need to change it - just putting it into Qlik and letting it run against your database. Qlik itself doesn't execute the sql else just transfers per driver the statement and received later the result. Only the database and the used driver must be capable for the applied features and syntax.
If this isn't the case you should discard the sql and creating the calendar directly with Qlik logic. The following posting provides a lot of links about calendars in general as well as specialized calendars, like 4-4-5 or fiscal calendars: