Print Page | Close Window

How to Use Or in SQL Statement

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=12219
Printed Date: 30 March 2026 at 11:31pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: How to Use Or in SQL Statement
Posted By: Misty
Subject: How to Use Or in SQL Statement
Date 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!




Replies:
Posted By: ngaisteve1
Date Posted: 18 October 2004 at 12:43am

You can try to change to:

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

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



Posted By: Misty
Date Posted: 18 October 2004 at 1:02am
Unfortunately, it didn't work. Does anyone have any other ideas?


Posted By: Phat
Date 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;


Posted By: Misty
Date 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?


Posted By: zaboss
Date Posted: 18 October 2004 at 2:19am
Your  initial SQL sounds OK. What error do you get?

-------------
Cristian Banu
http://www.soft4web.ro - Soft 4 web


Posted By: Phat
Date 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.


Posted By: michael
Date Posted: 18 October 2004 at 9:44am
strSQL=" AND ListingType IN ('Featured','National')"

-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: Misty
Date Posted: 18 October 2004 at 1:23pm

The following code worked for me: strSQL= strSQL & " and ListingType IN ('Featured','National')"

Michael, Thank you for helping me to figure out how to do this!



Posted By: michael
Date Posted: 19 October 2004 at 10:24am
Remember that is not an OR statement but should work for something simple as you do. It would return true if you had a listing type called 'Feature' without the last D as well....

-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: ljamal
Date Posted: 19 October 2004 at 12:49pm
No, it wouldn't it only returned those in which the field states Featured of National. The complete field must only contain the comma delineated terms.

-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming


Posted By: michael
Date Posted: 19 October 2004 at 1:47pm
You are right, mixed that up, sorry

-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net