Minor, but important fixes in MSSQL support

Fixed a few bugs found when performing more thorough testing of the MSSQL support.
Added script for creating the raw_stats table in MSSQL.