i have problem with my sql.The problem is a result data from the table is not same like i put in parameter.
can you check what’s wrong with my code?.
This is my code:-
select distinct convert(varchar(10),a.entered,103) as
daterange from customer
where
((a.entered BETWEEN convert(varchar(10),&daterangefrom,103) AND convert(varchar(10),&daterangeto,103)) or (convert(varchar(10),&daterangefrom,103) =' ' AND convert(varchar(10),&daterangeto,103) =' '))
You are comparing the dates as strings, but the dd/mm/yyyy format that you are using doesn’t work for such comparisons. For example,
'2/4/1976' > '1/9/2012'.Compare the dates as dates:
Alternatively, use the ISO 8601 based yyyy-mm-dd format, which does work as string comparisons: