The error message is
Query failed, possibly due to a malformed statement.
however I don't change anything in the statement and then it runs successfully.
This is very strange. I use a lot of SQLExecutors / SQLCreators, and I've never had this issue.
Can you provide us with a minimal sample workspace that demonstrates the issue, as well as a complete log?
If that is not an option, you should consider contacting Safe support.
You tried to include the connection in "tool options - Database connections" before you created your SQL transformation, this must be because your desktop is not recognizing the database connection.
I copied the first few transformers to a new workspace to send . but cannot get it to error!
my original workspace is also now behaving. I guess it may have something to do with maiaeam's answer and the connection is now recognised somehow.