No matter what is tried our our end, a custom query errors out and trying to repair it wipes it clean. is there any documentation or language definitions for custom queries on a SQL Server on premise instance of Sugar?
There just isnt enough info there to answer your question. What is the Query? Where are you putting it? What do you mean "Repair" it?
What version are you on?
Are you trying to use SQL instead of SugarQuery on 7.9?
If so, you may need to review the notes on prepared statements:
Use of prepared statements in Sugar 7.9 « Sugar Developer Blog – SugarCRM
Retrieving data ...