Corrected a few dynamic sql oversights