changes to mssql query construct

moved the where clause to the variable