Results 1 to 3 of 3

Thread: Conditioned Query

  1. #1
    Join Date
    Jan 2006

    Conditioned Query

    hi all
    I am in need to create a 'basic' search engine. There are 4 inputs which could narrow the search, these are:
    $_WhiteName, $_BlackName, $_Result and $_Tourn

    I need to check if the user is looking for all the games:
    -in the database (meaning all fields are empty)
    -of a specific player (meaning both fields [$_WhiteName and $_BlackName] have the near same value
    -of a specific tournament ($_WhiteName AND $_BlackName are empty but $_Tourn is not)
    -Won/Lost/Drawn of a specific player ($_White/$_Black Name with near same value, $_Tourn empty but $_Result not)
    -Won/Lost/Drawn of a specific player in a specific tournament ($_White/$_Black Name with near same value, $_Tourn and $_Result not empty)

    1. So I thought constructing the query sentence based on a bunch of IFs and then simply echo everything the Database returns (already filtered by the query)
    What do you think about this idea?

    2. I tried a test sentence:
    SELECT * FROM BiblioPartidas WHERE WhiteName LIKE $_WhiteName AND BlackName NOT LIKE $_WhiteName
    but it returned rows where $_WhiteName is equal to BlackName so im a bit lost here...
    How would I write a correct sentence defining such criterias?

  2. #2
    Join Date
    Jan 2006
    SELECT * FROM BiblioPartidas WHERE ltrim(rtrim(WhiteName)) LIKE ltrim(rtrim($_WhiteName)) AND ltrim(rtrim(BlackName)) NOT LIKE ltrim(rtrim($_WhiteName))

    check if this works if dosnt use '%' before and after your vars. You will have to use sp_executesql to do that creating a query string

  3. #3
    Join Date
    Sep 2002
    Keep in mind that sp_executesql is available in sql server only.

Posting Permissions

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