Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - How to Use Or in SQL Statement
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

How to Use Or in SQL Statement

 Post Reply Post Reply Page  12>
Author
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Topic: How to Use Or in SQL Statement
    Posted: 18 October 2004 at 12:13am

I would like to know how to use Or in your SQL Statement. Please look at the below SQL Statement that I have:

              'Start SQL statement
              strSQL = "Select * From SpaStore, Area, State"
              strSQL = strSQL & " where SpaStore.Area = Area.AreaID"
              strSQL = strSQL & " and State.State = Area.State"

              strSQL = strSQL & " and ListingType='Featured' or 'National'"
    strSQL = strSQL & " and Approve=0"
    strSQL = strSQL & " Order By SpaStoreName"

I would like for records with both listingtype of Featured and National to show up. But this sql statement won't work. How do I get records for both listing types? Thanks!

Back to Top
ngaisteve1 View Drop Down
Groupie
Groupie
Avatar

Joined: 26 December 2002
Location: Malaysia
Status: Offline
Points: 169
Post Options Post Options   Thanks (0) Thanks(0)   Quote ngaisteve1 Quote  Post ReplyReply Direct Link To This Post Posted: 18 October 2004 at 12:43am

You can try to change to:

strSQL = strSQL & " and (ListingType='Featured' "

strSQL = strSQL & " OR ListingType='National') "

Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Posted: 18 October 2004 at 1:02am
Unfortunately, it didn't work. Does anyone have any other ideas?
Back to Top
Phat View Drop Down
Senior Member
Senior Member


Joined: 23 February 2003
Status: Offline
Points: 386
Post Options Post Options   Thanks (0) Thanks(0)   Quote Phat Quote  Post ReplyReply Direct Link To This Post Posted: 18 October 2004 at 1:08am
Try Something like

SELECT SpaStore.ListingType, SpaStore.Approve, SpaStore.SpaStoreName
FROM SpaStore
WHERE (((SpaStore.ListingType)="Featured")) OR (((SpaStore.ListingType)="National") AND ((SpaStore.Approve)="0"))
ORDER BY SpaStore.SpaStoreName;
Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Posted: 18 October 2004 at 1:48am
It is very important for me to stay with the sql statement that I have. I need to be able to join the three tables. Does anyone have other ideas on how I might be able to work out this problem?
Back to Top
zaboss View Drop Down
Senior Member
Senior Member


Joined: 20 August 2002
Location: Romania
Status: Offline
Points: 454
Post Options Post Options   Thanks (0) Thanks(0)   Quote zaboss Quote  Post ReplyReply Direct Link To This Post Posted: 18 October 2004 at 2:19am
Your  initial SQL sounds OK. What error do you get?
Cristian Banu
Soft 4 web
Back to Top
Phat View Drop Down
Senior Member
Senior Member


Joined: 23 February 2003
Status: Offline
Points: 386
Post Options Post Options   Thanks (0) Thanks(0)   Quote Phat Quote  Post ReplyReply Direct Link To This Post Posted: 18 October 2004 at 4:02am
Build the tables in access and then use the query builder. Much faster and easier.

If you do not know access then put up a list of tables and fields and i will build it for you.
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 18 October 2004 at 9:44am
strSQL=" AND ListingType IN ('Featured','National')"
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.