I have two varchar(30), startDate and endDate coloumn and it has dates values and also nulls in that coloumn. I want to compare the date range in sql server 2005/2008. someting like
WHERE e2.type=1
AND coloumn1 between convert(datetime,startDate,101) and convert(datetime,endDate,101)
When i try to execute it gives me an error
the conversion of varchar data type to a datetime data type resulted in an out-of-range value.
That error message indicates that the value stored in the varchar cannot be converted (by SQL) into a datetime. You will need to drill down in your data and locate the problem row(s), which can be a tricky thing to do. Start with something like:
…and the same for EndDate. You will have to play around with this, as string-to-date conversion is can get tricky fast. (Needless to say, you would be much better off storing datetime values as datetime values. If you can change your table structure, do so!)