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
 General SQL Server Forums
 New to SQL Server Programming
 select * where date = someday not finding all days

Author  Topic 

fuzzyip
Starting Member

35 Posts

Posted - 2008-07-18 : 12:34:38
I've got a table of about 150,000 entries with a products and a sold column.

The sold column is in datetime format.

When I do a manual query...

select *
from ansold
where datesold between '7/4/2008 0:00:01 am' and '7/4/2008 23:59:59 pm'

It picks up about 1251 entries, but if I open the table, and export to excel and sort by date, I see that there are 5604 entries on the 4th of July.

Why isn't my query able to pick up those dates?

I made my query into a stored proc also with...


select *
from ANSold
where datesold >= @datebegin
and datesold < dateadd (d, +1, @dateend)
and city like '%'+@state+'%'
order by datesold


This also picks up only 1251 out of 5604



Anyone have any ideas? I'm stumped.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-07-18 : 12:57:02
What does this return:

select count(*)
from ansold
where datesold >= '7/4/2008' and datesold < '7/5/2008'

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

fuzzyip
Starting Member

35 Posts

Posted - 2008-07-18 : 13:02:35
quote:
Originally posted by tkizer

What does this return:

select count(*)
from ansold
where datesold >= '7/4/2008' and datesold < '7/5/2008'

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog



returns
1251
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-07-18 : 13:06:03
Then you've only got 1,251 rows for July 4th. Excel is wrong.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -