Say, if I need to select records from the database where the date field is in a particular time frame. The select query would be this:
SELECT * FROM [MyTable] WHERE [Date] >= @RangeBegin AND [Date] <= @RangeEnd;
But I have a little condition when the Date field might be empty or invalid. In that case the date value should be taken from @DefaultDate.
How do you put all this into SQL?
Since you say that the date can be invalid I assume you have stored dates as varchar.
You can use isdate to check if the date is valid.