Results 1 to 3 of 3

Thread: I need help for a sql statement

  1. #1
    Join Date
    May 2004
    Location
    NewYork, USA
    Posts
    175
    Thanks
    25
    Thanked 0 Times in 0 Posts

    Default I need help for a sql statement

    Hi

    I have a statement somthing like this


    Code:
    sSQL="SELECT * FROM tbllinks where tbllinks.Active = 'Y' and Name like '%" & sKeywords & "%'" & _
    "or URL like '%" & sKeywords & "%'" & _
    "or Description LIKE '%" & sKeywords & "%'" & _
    "or Keywords LIKE '%" & sKeywords & "%'" & _
    "or Contact_Name LIKE '%" & sKeywords & "%'" & _
    "or Contact_Email LIKE '%" & sKeywords & "%'" & _
    "or hit LIKE '%" & sKeywords & "%' order by hit desc;"


    it's supposed to select only those who have Y value in Active colum however it also selects those who have N value.

    I also tried this one:


    Code:
     
    sSQL="SELECT tbllinks.ID,tbllinks.Name,tbllinks.URL,tbllinks.Description,tbllinks.Keywords,tbllinks.Contact_Name,tbllinks.Contact_Email,tbllinks.hit FROM tbllinks where tbllinks.Active = 'Y' and Name like '%" & sKeywords & "%'" & _
    "or URL like '%" & sKeywords & "%'" & _
    "or Description LIKE '%" & sKeywords & "%'" & _
    "or Keywords LIKE '%" & sKeywords & "%'" & _
    "or Contact_Name LIKE '%" & sKeywords & "%'" & _
    "or Contact_Email LIKE '%" & sKeywords & "%'" & _
    "or hit LIKE '%" & sKeywords & "%' order by hit desc;"


    what is wrong in this statement?

  2. #2
    Join Date
    Feb 2004
    Posts
    4,903
    Thanks
    2
    Thanked 134 Times in 113 Posts

    Default

    You need to use brackets to seperate the ORs from the ANDs so that the ANDs aren't overiden:

    Code:
    sSQL="SELECT * FROM tbllinks where tbllinks.Active = 'Y' and (Name like '%" & sKeywords & "%'" & _
    "or URL like '%" & sKeywords & "%'" & _
    "or Description LIKE '%" & sKeywords & "%'" & _
    "or Keywords LIKE '%" & sKeywords & "%'" & _
    "or Contact_Name LIKE '%" & sKeywords & "%'" & _
    "or Contact_Email LIKE '%" & sKeywords & "%'" & _
    "or hit LIKE '%" & sKeywords & "%') order by hit desc;"
    Warren Ashcroft
    Red Fox UK Limited - Pioneers in Internet Technology
    http://www.redfoxuk.com
    w.ashcroft [at] redfoxuk.com

    NOTE: Forum Private Messaging should not be used to contact staff with support queries.

  3. The Following User Says Thank You to Warren Ashcroft For This Useful Post:

    RFH Reseller: HostCan (26th January 2008)

  4. #3
    Join Date
    May 2004
    Location
    NewYork, USA
    Posts
    175
    Thanks
    25
    Thanked 0 Times in 0 Posts

    Default

    Thank you I really appriciate.
    Now it works !

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 9
    Last Post: 20th February 2007, 08:17 PM
  2. Replies: 2
    Last Post: 2nd August 2006, 03:04 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •