• I would use a combination.  Run the execute task to run your pre-queries.  Use the data driven task to run the query that outputs to the file. 

    The data driven task is well documented elsewhere.  You should have no trouble finding out how to do this.