Slightly more MSSQL friendly MySQL code. WIP.