ENhance SQL query. closes #2405