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, 12: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, 07: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, 01: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, 04: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, 10: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, 07: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, 11:38 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
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, 04: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, 10: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




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

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




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek