Fixed bugs in SQL, format() string. Also indented docstring.

Here are some trivial fixes to bugs that I found when running the script for the first time.