Removed un-used variables, trimmed unnecessarily explicit name-spaces, f...

...ixed SQL data-type typo, fixed accidental variable trampling and highlighted some potentially subtle SQL data-type bugs.