Fix sql error. closes #2268