Monty Sing:
This query was working correct 2 days back but today I executed the same query and showing below error
No. It wasn't. You simply failed to realise it was getting the dates wrong. What you intended as 12th Jan was interpreted (correctly. Your code is where the error is) as 1st Dec.
Your SQL code is being created somewhere, no doubt, and this is getting the dates wrong. SQL dates are not region dependent. They recognise a general (ANSI-92) SQL standard format hich is m/d/y, regardless of where in the world your SQL is running. Hence, your code should be :
- SELECT * FROM [Customer] WHERE ([OrderDate] BETWEEN '1/2/2012' AND '1/14/2012') AND ([Item]='Dell')
assuming your date range is 2nd Jan 2012 to 14th Jan 2012. Whatever code you have that creates this string should also be amended to reflect this change.