Try to avoid Scripting
A well crafted SQL statement is a thing on beauty, and writing one gives a great deal of satisfaction. But creating art is not the job.
If there is no other choice but using a script, avoid wasting time honing, refining, and later augmenting your own.
Download industrial-strength scripts from a trusted source. But read and understand them before using in production.