Personally, I think that's a bad idea to run the SQL query on events and especially on "Document Open". I would rather suggest you to use QlikView Direct Discovery which fetches the data from database without reload the data from QlikView application. With new service release QlikTech enhanced the Direct Discovery functionality.