Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 16th, 2002, 01:55 PM
JohnSmith JohnSmith is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Location: Canada
Posts: 10 JohnSmith User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Why won't this select Query return any rows?

Hello, this is my first post here, i hope that someone can help me out.

I have a pretty complex SQL query, which is supposed to return a count of how many items are within a given time period.

however, there is a little "twist" to this, the items can open and close. so they have to be open during the period in question.

which means, that there is one of 5 possible criteria that will satisfy this, either they:

open before, and close after the period
open before, and close within the period
open within, and close within the period
open within, and close after the period

so, this is the SQL that i was using:

SELECT COUNT(*) FROM TBL_BQDATA WHERE ((DATA_ADDEDDATETIME > 6/1/2002 AND Closed_DATE <= 6/30/2002) OR (DATA_ADDEDDATETIME <= 6/1/2002 AND Closed_DATE > 6/30/2002) OR (DATA_ADDEDDATETIME <= 6/30/2002 AND Closed_DATE > 6/30/2002 AND DATA_ADDEDDATETIME > 6/1/2002) OR (DATA_ADDEDDATETIME <= 6/1/2002 AND Closed_DATE <= 6/30/2002 AND Closed_DATE > 6/1/2002)) AND (DATA_ADDEDDATETIME <= Closed_DATE);

The logic seems to be solid, but, i get no rows back. I have verified that there is in fact data in the table. I tried running this in the query builder in MS-Access 2002, and i got no results back as well. I took a screen shot to be clear, it shows the table data, as well as the query, one version nicely formatted, and one of just raw characters.



why don't i get anything back?

Reply With Quote
  #2  
Old September 17th, 2002, 08:30 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
firstly, i dont actually know SQL, so im going to be brief, basically what i would do is start from a small query,

SELECT count(*) FROM TBL_BQDATA

and build up your query from there, testing each time you add a condition,

apart from that your query looks like it should work??

make sure that your test data, covers all possibilities as well

Reply With Quote
  #3  
Old September 18th, 2002, 02:36 AM
JohnSmith JohnSmith is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Location: Canada
Posts: 10 JohnSmith User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
yep, start small and build up, that's what i'm doing. i've already built tons of graphs the small way.

thanks anyway...

Reply With Quote
  #4  
Old September 18th, 2002, 05:13 AM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
on secon look at your query try this as the last bit

Closed_DATE > 6/1/2002 AND DATA_ADDEDDATETIME <= Closed_DATE));

ive got no idea if it will work, but give it a try

Reply With Quote
  #5  
Old September 18th, 2002, 11:18 AM
JohnSmith JohnSmith is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Location: Canada
Posts: 10 JohnSmith User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
uh.. isn't that what i did write?

I put:

Closed_DATE > 6/1/2002)) AND (DATA_ADDEDDATETIME <= Closed_DATE);

you said:

Closed_DATE > 6/1/2002 AND DATA_ADDEDDATETIME <= Closed_DATE));

The only difference is the parentheses. in any case, the last condition, is only a check to make sure that the open date is before the closed, to ensure that nothign weird is going on.

i thought that might be the problem too, so i removed the entire last condition, it still doesn't work.

Reply With Quote
  #6  
Old September 18th, 2002, 08:03 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
hmmm, im just having a stab in the dark here but maybe try this???


SELECT COUNT(*) FROM TBL_BQDATA WHERE (DATA_ADDEDDATETIME > 6/1/2002 AND Closed_DATE <= 6/30/2002 OR DATA_ADDEDDATETIME <= 6/1/2002 AND Closed_DATE > 6/30/2002 OR DATA_ADDEDDATETIME <= 6/30/2002 AND Closed_DATE > 6/30/2002 AND DATA_ADDEDDATETIME > 6/1/2002 OR DATA_ADDEDDATETIME <= 6/1/2002 AND Closed_DATE <= 6/30/2002 AND Closed_DATE > 6/1/2002 AND DATA_ADDEDDATETIME <= Closed_DATE);

Reply With Quote
  #7  
Old September 25th, 2002, 12:38 PM
JohnSmith JohnSmith is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Location: Canada
Posts: 10 JohnSmith User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I am such an idiot. you know what the problem was?

I forgot to put # signs around the dates.

i guess hash can fix anything!

Reply With Quote
  #8  
Old September 25th, 2002, 05:47 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
lol, im supprised no one picked it up, even my *slams head against desk*

DOH

Reply With Quote
  #9  
Old October 11th, 2002, 11:37 AM
Dai Dai is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: UK
Posts: 3 Dai User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Logic could also be simplified to (pseudocode)

(opendate < end of period) AND (close date > start of period)

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > Why won't this select Query return any rows?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT