Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - SQL problem
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

SQL problem

 Post Reply Post Reply
Author
ainsworth14 View Drop Down
Groupie
Groupie


Joined: 05 August 2003
Location: United Kingdom
Status: Offline
Points: 62
Post Options Post Options   Thanks (0) Thanks(0)   Quote ainsworth14 Quote  Post ReplyReply Direct Link To This Post Topic: SQL problem
    Posted: 27 April 2005 at 4:22pm
Hi all, i am trying to query my access table from my website with the following SQL:
 
record_sql = "SELECT * FROM record_overview WHERE ARTIST LIKE '%" & searchword & "%' OR TITLE LIKE '%" & searchword & "%' OR DESCRIPTION LIKE '%" & searchword & "%' AND STOCK > 0 ORDER BY ARTIST ASC"
 
the problem is that it all works fine except for the AND Stock >0 bit - it still brings back items that have 0 in the field.
 
any ideas?
 
thanks
mark


Edited by ainsworth14 - 27 April 2005 at 4:26pm
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: 27 April 2005 at 4:54pm
It's like High-School Math. Put brackets around it
 
record_sql = "SELECT * FROM record_overview WHERE (ARTIST LIKE '%" & searchword & "%' OR TITLE LIKE '%" & searchword & "%' OR DESCRIPTION LIKE '%" & searchword & "%') AND STOCK > 0 ORDER BY ARTIST ASC"
Back to Top
ainsworth14 View Drop Down
Groupie
Groupie


Joined: 05 August 2003
Location: United Kingdom
Status: Offline
Points: 62
Post Options Post Options   Thanks (0) Thanks(0)   Quote ainsworth14 Quote  Post ReplyReply Direct Link To This Post Posted: 27 April 2005 at 5:09pm
yup worked a treat
 
thanks
 
ps i'm fairly new to working with sql statements!
Back to Top
Lofty View Drop Down
Newbie
Newbie
Avatar

Joined: 03 April 2005
Status: Offline
Points: 19
Post Options Post Options   Thanks (0) Thanks(0)   Quote Lofty Quote  Post ReplyReply Direct Link To This Post Posted: 28 April 2005 at 3:19am
aye. bit more of an explanation.   using Or in the sql statement is like resetting Where statement, it whipes all the previous where & And stuff each Or is starting fresh.

so the stock > 0 is only applicable to doing a search for DESCRIPTION

if you went
ARTIST LIKE '%" & searchword & "%' AND STOCK > 0 OR TITLE LIKE '%" & searchword & "%' AND STOCK > 0 OR DESCRIPTION LIKE '%" & searchword & "%' AND STOCK > 0

that would also work..  but obviously the brackets is a much better solution. I just thought ya might want to know why.
Back to Top
ainsworth14 View Drop Down
Groupie
Groupie


Joined: 05 August 2003
Location: United Kingdom
Status: Offline
Points: 62
Post Options Post Options   Thanks (0) Thanks(0)   Quote ainsworth14 Quote  Post ReplyReply Direct Link To This Post Posted: 28 April 2005 at 2:21pm

thanks a lot for the explanation its a great help

 
thanks
mark
Back to Top
 Post Reply Post Reply

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.