11-16-2009, 09:17 PM
Just highlight a SQL statement in any text editor and press a hot key for the macro below to reformat the SQL into a readable format indented for each clause.
Macro format sql
Trigger W3
Macro format sql
Trigger W3
str s.getsel
s - " "
s + " "
s.replacerx("\s+"," ",1)
s.replacerx("\[","",1)
s.replacerx("\]","",1)
s.replacerx("\sselect\s","[]select[][009]",1)
s.replacerx("\sdelete from\s","[]deletexfrom[][009]",1)
s.replacerx("\sinsert into\s","[]insertxinto[][009]",1)
s.replacerx("\supdate\s","[]update[][009]",1)
s.replacerx("\sdelete\s","[]delete[][009]",1)
s.replacerx("\sset\s","[]set[][009]",1)
s.replacerx("\sfrom\s","[]from[][009]",1)
s.replacerx("\sfull outer join\s","[]fullxouterxjoin[][009]",1)
s.replacerx("\sleft outer join\s","[]leftxouterxjoin[][009]",1)
s.replacerx("\sright outer join\s","[]rightxouterxjoin[][009]",1)
s.replacerx("\sleft join\s","[]leftxjoin[][009]",1)
s.replacerx("\sright join\s","[]rightxjoin[][009]",1)
s.replacerx("\sinner join\s","[]innerxjoin[][009]",1)
s.replacerx("\scross join\s","[]crossxjoin[][009]",1)
s.replacerx("\sjoin\s","[]join[][009]",1)
s.replacerx("\swhere\s","[]where[][009]",1)
s.replacerx("\sgroup by\s","[]groupxby[][009]",1)
s.replacerx("\sorder by\s","[]orderxby[][009]",1)
s.replacerx("\shaving\s","[]having[][009]",1)
s.replacerx(",",",[][009]",1)
s.replacerx(" and ","[]and[][009]",1)
s.replacerx(" or ","[]or[][009]",1)
s.replacerx(" end ","[]end[]",1)
s.replacerx(" go ","[]go[]",1)
s.replacerx("\sreturn ","[]return ",1)
s.replacerx("\n\t\n\t","[][009]",1)
s.replacerx("\n\n","[]",1)
s.replacerx("\n\n","[]",1)
s.replacerx("insertxinto","insert into",1)
s.replacerx("fullxouterxjoin","full outer join",1)
s.replacerx("leftxouterxjoin","left outer join",1)
s.replacerx("rightxouterxjoin","right outer join",1)
s.replacerx("leftxjoin","left join",1)
s.replacerx("rightxjoin","right join",1)
s.replacerx("innerxjoin","inner join",1)
s.replacerx("crossxjoin","cross join",1)
s.replacerx("groupxby","group by",1)
s.replacerx("orderxby","order by",1)
s.replacerx("\t ","[009]",1)
s.setsel