Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy SQL Query Problem

    Hi all,
    i have made a SEARCH page with the following inputs:

    KEY
    WARD
    BLOCK
    ZONE
    TITLE
    SUBT
    *All fields are VARCHAR TYPE.

    I need to make a query such that whenever the user enters data, result comes, be it 1 input, all inputs or combination of inputs.
    This is working in all input fields, except for KEY & WARD. They are showing all records & not filtering as what is being selected.

    The query is written below, plz. suggest me something.

    -- shows comment

    SELECT DISTINCT
    FROM blah blah blah................
    WHERE
    --CONTAINS(viewname.*,@SKey)
    (
    (c.block LIKE '%' + @SKey +'%') or (c.zone LIKE '%' + @SKey +'%')
    )

    or

    -- CONTAINS (c.*, '*@ward*')
    ((c.ward = @ward) or (ward <> ''))
    --- (c.ward LIKE '%' + @ward +'%')
    AND
    -- (@block = '') OR (c.block LIKE '%' + @block +'%')
    --(c.block = @block )
    (c.block LIKE '%' + @block +'%')

    --AND ((@zone = '') OR (c.zone = @zone)
    AND( c.zone LIKE '%' + @zone +'%')
    -- or (@zone = '')

    --AND ((@title = '') OR ( c.co_title = @title)
    AND (c.title LIKE '%' + @title +'%')
    -- or (@title = '')
    --AND ((@subt = '') OR (c.co_subt = @subt)
    AND (c.subt LIKE '%' + @subt +'%')
    --or (@subt = '')

    I feel i need to place the ORs and ANDs properly.

    Plz. help me out!
    Regards
    Monica

  • #2
    New Coder
    Join Date
    Aug 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    whats the name of your table and each fieldname???

    try to SELECT * FROM <tablename> where fieldname = condition1 or condition2....


  •  

    Posting Permissions

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