fixed exporting query with variables