Error while executing query using send attachment
the solution was to specify the database prefix in the sql query in the @query parameter. After lot of scratch on my head i realized without prefixing DB name+Schema in Exec @query it will not work.

Did not work: @query = 'SELECT fields FROM table'
Works: @query = 'SELECT fields FROM database..table'