Wrox Programmer Forums
|
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
 
Old July 2nd, 2003, 07:00 PM
Authorized User
 
Join Date: Jun 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?
 
Old July 3rd, 2003, 03:49 AM
Authorized User
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to psychadelic
Default

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#
 
Old July 3rd, 2003, 07:32 AM
Authorized User
 
Join Date: Jun 2003
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old July 3rd, 2003, 01:26 PM
Authorized User
 
Join Date: Jun 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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 ;]
 
Old July 28th, 2003, 09:00 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 196
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jmss66
Default

You can also use:

SELECT * FROM TABLE WHERE DATE BETWEEN #01/01/01# AND #01/02/01#
 
Old April 6th, 2004, 06:23 AM
Registered User
 
Join Date: Mar 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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! :)
 
Old October 5th, 2004, 11:59 AM
Registered User
 
Join Date: Oct 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

 
Old October 5th, 2004, 12:46 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple command question... ironchef JSP Basics 1 November 23rd, 2007 12:13 AM
Command Button Question eoghang Excel VBA 2 September 25th, 2006 08:33 PM
About SQL command hoailing22 ASP.NET 1.0 and 1.1 Basics 8 May 19th, 2005 07:31 PM
executing sql command redface Crystal Reports 0 April 6th, 2005 05:14 PM
Sql Command hanzahalka ADO.NET 0 July 8th, 2003 09:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.