Fix sql error. references #2504