MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 3rd, 2004, 10:51 AM
GeorgeR GeorgeR is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 5 GeorgeR User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
SQL query and dates

Hi, im trying to write a sql query to check if dates are in the db,
ias it is it is telling me the dates are there and their not. any help would be great.
George

here's what i have...

SQL2 = "SELECT * FROM reservations WHERE" _
& "(arvdate >=#" & request("arvdate") & "# AND endate <= #" & request("endate") & "#) " _
& "OR " _
& "(arvdate >=#" & request("arvdate") & "# AND endate >= #" & request("endate") & "#) " _
& " AND idrent = " & idrent _
& " AND confirmation = 1" _
& " ORDER BY arvdate"

Reply With Quote
  #2  
Old August 3rd, 2004, 11:29 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,654 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 6 Days 12 h 49 m 28 sec
Reputation Power: 981
you have
Code:
 WHERE (arvdate >=#A# AND endate <= #E#) 
    OR (arvdate >=#A# AND endate >= #E#) 
   AND idrent = I
   AND confirmation = 1


first of all, SQL Server requires quotes to delimit date strings,
not hash marks, so this is probably an Access query, but that's
a minor issue

you have

... WHERE X OR Y AND P AND Q

this is evaluated as

... WHERE X OR ( Y AND P AND Q )

what you want, logically, is

... WHERE ( X OR Y ) AND P AND Q

and therefore you will have to supply the additional parentheses
Code:
 WHERE (
       (arvdate >=#A# AND endate <= #E#) 
    OR (arvdate >=#A# AND endate >= #E#) 
       )
   AND idrent = I
   AND confirmation = 1


furthermore, the way you have the >= and <= operators coded,
i think there's an error there too

you have two compound conditions, each involving arvdate and endate,
and the way you have them coded, enddate doesn't matter, as long as
arvdate >=#A#
__________________
r937.com | rudy.ca

Reply With Quote
  #3  
Old August 3rd, 2004, 11:49 AM
GeorgeR GeorgeR is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 5 GeorgeR User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks,

Ill give it a try.

Reply With Quote
  #4  
Old August 3rd, 2004, 12:30 PM
GeorgeR GeorgeR is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 5 GeorgeR User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
That didnt work either

i guess ill just keep trying

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > SQL query and dates


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 1 hosted by Hostway