|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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" |
|
#2
|
||||
|
||||
|
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# |
|
#3
|
|||
|
|||
|
Thanks,
Ill give it a try.
|
|
#4
|
|||
|
|||
|
That didnt work either
i guess ill just keep trying
|
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > SQL query and dates |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|