You may see similar error while posting ledger journal:
Posting - Journal
Cannot select a record in ().
The SQL database has issued an error.
The journal is not posted and the update is canceled.
SQL error description: [Microsoft][SQL Native Client][SQL Server]Invalid object name '#ax_tmp_dmo3_52_0'.
This error is caused by collecting Query plans while doing SQL tracing. To avoid this error you need to disable Query plan collection in Tools | Options on SQL tab.