Fix sql downloads
Merge pull request #1196 from nlegoff/fixtests

[3.8.6] Fix report sql queries for downloads