Answer
A few specific, documented gotchas explain both symptoms: Context-Substitution-Variable-style tokens, like a #END_OF_LAST_MONTH#-style placeholder, used inside an IAL/Quick Report's SQL are automatically resolved by the Quick Report engine at runtime, but the plain SQL Query Tool does NOT understand or resolve these tokens at all — running the exact same SQL there requires substituting in literal, concrete date values by hand instead, which is exactly why identical SQL can run fine as a Quick Report but fail in the SQL Query Tool. Separately, for Quick Report's Export-to-Excel path specifically, several documented limitations apply: a query that doesn't literally start with the SELECT keyword, for example one starting with a WITH clause, isn't supported for Excel export at all, use an Output Channel export instead in that case; bind arguments can't appear inside a GROUP BY expression; and parameter NAMES, though not parameter VALUES, can't contain non-English characters such as Å, Ä, or Ö. Checking a failing query against each of these specific limitations, rather than assuming it's a general date-formatting problem, is the fastest way to diagnose an Excel-export-specific failure.