avoid invalid sql statement when where is empty