Corrected the errors, and mssql query formulation issues