December 13, 2008 at 8:51 am
Hi all,
i am Jayateertha from Mysore India, I have a Problem in sql server 2005 while i was running a sql query
Select Name,City,registeredDate from tblMembers where RegisteredDate >= '12/09/2008' and RegisteredDate<= '12/12/2008'
it should display all the Name,city and RegisteredDate inclusive of Both the dates but it is not displaying the records of Last date (12/12/2008)
December 13, 2008 at 9:04 am
jai_anand2004 (12/13/2008)
Hi all,i am Jayateertha from Mysore India, I have a Problem in sql server 2005 while i was running a sql query
Select Name,City,registeredDate from tblMembers where RegisteredDate >= '12/09/2008' and RegisteredDate<= '12/12/2008'
it should display all the Name,city and RegisteredDate inclusive of Both the dates but it is not displaying the records of Last date (12/12/2008)
thats because if you don't specify minutes and seconds they default to 00:00:00. so change query to < '13/12/2008'
---------------------------------------------------------------------
December 13, 2008 at 9:14 am
the datetime data type stores both date and time.
so the result of
RegisteredDate<= '12/12/2008'
will output all dates less than on equal to 2008-12-12 00:00:00.000
if the record has a RegisteredDate colums's value as 2008-12-12 10:30:00.000, it wont be fetched using the condition you've written.
To overcome this either change the query to
RegisteredDate< '12/13/2008'
or RegisteredDate <='2008-12-12 23:59:59.997'
December 13, 2008 at 9:26 am
sorry didn't know settings on your server. if format is mm/dd/yyyy then yes use
RegisteredDate< '12/13/2008'
so my syntax would have errored for you.
I come from a sensible part of the world where days come before months 🙂
---------------------------------------------------------------------
December 13, 2008 at 9:51 am
well i too presumed the format was mmddyyyy..
he can still twick the query even ih he doesnt know the server's date format by executing either set dateformat 'dmy' OR set dateformat 'mdy' before running his query.... 😉
December 13, 2008 at 7:51 pm
So, Jayateertha from Mysore India... did any of those answer your question?
--Jeff Moden
Change is inevitable... Change for the better is not.
December 14, 2008 at 5:54 am
Seems he forgot to come back to see the responses!!
His visits count still is 1.
December 16, 2008 at 3:16 am
Thanks all ... surely it worked.
December 16, 2008 at 7:28 pm
Cool... thanks for the feedback.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply