repaired sql for search and updated code for date available sql comparisons