 |
| VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

July 2nd, 2003, 07:00 PM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
SQL "where" command question
Having trouble with the WHERE command used multiple times, I don't have an SQL reference handy so I'm asking here =o)
Receiving an error when I pass the following type of statement..
"SELECT * FROM TABLE WHERE DATE > 01/01/01 AND WHERE DATE < 01/02/01"
says operator missing. anyone know the correct format for this type of sql queery?
|
|

July 3rd, 2003, 03:49 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I think there is a little problem with the second WHERE...
Try this:
SELECT * FROM TABLE WHERE DATE > 01/01/01 AND DATE < 01/02/01
or this:
SELECT * FROM TABLE WHERE DATE > #01/01/01# AND DATE < #01/02/01#
|
|

July 3rd, 2003, 07:32 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You only need 1 WHERE clause so make you example look like this:
"SELECT * FROM TABLE WHERE DATE > 01/01/01 AND DATE < 01/02/01"
Kenny Alligood
|
|

July 3rd, 2003, 01:26 PM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for the help, however the posted solutions were incorrect. I found the problem, the ( and ) operators are neccessary if more than one comparison is made...ie.
select * from table where (date > date2 and date < date1)
Thanks for the help ;]
|
|

July 28th, 2003, 09:00 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You can also use:
SELECT * FROM TABLE WHERE DATE BETWEEN #01/01/01# AND #01/02/01#
|
|

April 6th, 2004, 06:23 AM
|
|
Registered User
|
|
Join Date: Mar 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I was going to pose a Q about the where clause not working with dates in access databases .... but the last answer solved my problem. So thanks Jmss66. or as they say in the middle east.. Shukran Habibi! :)
|
|

October 5th, 2004, 11:59 AM
|
|
Registered User
|
|
Join Date: Oct 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I have a similar problem to this, but it goes slightly further. I have this statement:
SELECT * FROM MATCHES WHERE (USER_ID = 10001 OR OPPONENT_ID = 10001) AND (MATCH_DATE between " & dateadd("d",-28,date) & " AND " & dateadd("d",148,date) & ") ORDER BY MATCH_DATE;"
Yet no matter how many entries I have between the dates, it still gives me no results. If I remove the date clause, it works fine.
Any help appreciated.
|
|

October 5th, 2004, 12:46 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
hi there.. to clarify this.. i have a lots of problem caused by DB's storings dates in dif. ways... the best solve i have to all of them is to do the date clause like this
(following you case)
...format(MATCH_DATE,'yyyymmdd') between " & format(dateadd("d",-28,date),"yyyymmdd") & " AND " & format(dateadd("d",148,date),"yyyymmdd") & "...
HTH
Gonzalo
|
|
 |