Fix for MSSQL compatibility. Tested against internal grail (H2) DB, MSSQL 2012, and MYSQL 5.6.15