Problem in developing a SQL Querry in QlikView sense
This may not be a direct answer but just a recommended way of managing long and relatively complex query.
Ensure that the query produces a resultset working with it outside of QlikView. Assuming that the query is good, my recommendation is to create a view with the query. Then in QlikView, just use a select query to extract data from the view. That will help keep your QlikView document clean and debugging may become simple.