Expression > Forums - Accueil > Expression Web and SuperPreview > Don't know how to write "where" and/or statement in VWD
Poser une questionPoser une question
 

Réponse proposéeDon't know how to write "where" and/or statement in VWD

  • mardi 3 novembre 2009 14:19Mike362 Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     

    Hi guys. I have made a search page which is databound to my SQL 2008 database of 17,000 books (I have a bookshop). My search page has 3 search boxes: Author, Title and Keywords. I can easily configure VWD datalist control to look up values in the Author field but I want my customers to be able to enter search words into ALL or ANY of the boxes. I would have thought there should be a "where" process that adds a "and/or" or am I missing something. I know I may have to write the SQL query manually but don't know what to write. Any help much appreciated.

Toutes les réponses

  • mardi 3 novembre 2009 14:47paladyn Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     
    Mike, this isn't really a VWD forum, or SQL, for that matter. If I may suggest, you will probably want to ask this question over at http://forums.asp.net/. They have a lot of folks with extensive expertise in the areas you'll need to work with.

    Note that no matter where you inquire, you will need to provide more information concerning the specifics of your DB—table names, primary keys, foreign keys, etc., before anyone can help you to create a suitable SQL statement. Also, you will want to be sure that your DB is properly normalized and that the necessary keys exist. Just a suggestion...

    cheers,
    scott
    Plural's don't have apostrophe's. It seem's sometime's that any word's ending in "s" get a gratuitous apostrophe. Apostrophe's are used to indicate possessive's and elision's (contraction's or abbreviation's).
  • mardi 3 novembre 2009 14:49VeignMVPMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     Réponse proposée
    SQL on W3schools.com is a great resource:
    http://www.w3schools.com/SQl/default.asp

    What you will find is your SQL statement would be one of the following:

    WHERE Author LIKE '%AuthorTextBox%' AND Title LIKE '%TitleTextBox%' AND Keywords LIKE '%KeywordTextBox%'

    Then just manually add or remove sections of the where clause depending on what the user entered

    -or to do it in an automatic way (best way)-
    WHERE (Author LIKE '%AuthorTextBox%' OR AuthorTextBox = '') AND (Title LIKE '%TitleTextBox%' OR TitleTextBox = '') AND (Keywords  LIKE '%KeywordTextBox%' OR KeywordTextBox = '')

    Not sure if the % is used against a SQL Server database when using the Like statement
    --
    Chris Hanscom - Microsoft MVP
    On Facebook | On Twitter | Resource Center | Veign's Blog | Web Development Help

    Get a Complete Website Analysis by Veign
    • Proposé comme réponseVeignMVPmardi 3 novembre 2009 14:49
    •