Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 query returning wrong dif results

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2005-05-26 : 06:53:12
I have run 2 queries in query analyzer that I would expect to return the same results

select * from users where mydate>getdate()-1

select * from users where mydate >= CONVERT(datetime, '5/26/2005', 101) AND myDate < CONVERT(datetime, '5/27/2005', 101)


the second is only returning users until time of 3:30

Why would this be?

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2005-05-26 : 07:00:24
I wouldn't expect either of them to be reliable.
Look at the datediff functions in books online, there are much better ways of filtering dates.


Damian
Ita erat quando hic adveni.
Go to Top of Page

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2005-05-26 : 07:20:36
quote:
I wouldn't expect either of them to be reliable


Eh? The only way in which they aren't reliable is that the capitalization of the 'mydate' column name isn't consistent, and that only matters if the database is case-sensitive.

Sure, they're different queries: the first one returns rows where mydate is after a datetime 24 hours ago (including all future times), and the second to include all rows where mydate is a datetime sometime on 26th May 2005.

quote:
the second is only returning users until time of 3:30


If it is, the reason isn't in what you've shown us.
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2005-05-26 : 07:35:25
quote:

Eh? The only way in which they aren't reliable is that the capitalization of the 'mydate' column name isn't consistent, and that only matters if the database is case-sensitive.



Ooops,I read it wrong.
I thought the dates were being compared to varchars.... my mistake.


Damian
Ita erat quando hic adveni.
Go to Top of Page
   

- Advertisement -