Changed sql to be portable