Query to Search the Data

  • Hi,

    My requirement is,I want to search records,in my application,

    Example,

    Lnno

    Name

    Code

    SNo

    This are the Text box available on the screen where user will enter values in any one text box and based

    on this value records should be display.

    So I written query for this as,I enters some code in Code textbox,so this should retreive only the

    records for code like R0000299,but it displays all the records,

    Select A.* From CRM_Customer_Master A Join CRM_Loan_Master B

    On A.Lnno = B.Lnno

    Where A.Lnno Like '% %' Or SNo Like '% %' Or Code Like '%R0000299%' Or Name Like '% %')

    Kindly provide solution for this,as I need this urgently.

    Thanks in Advance!

  • Just copied well known link from very recent thread in this forum (just check one about "optional parameters in WHERE...")

    http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • Because you're using LIKE and the wild cards around a space, it's going to find every single record that matches up on any value that contains a space. You could build a dynamic query like what is suggested in Gail's article. In fact, if you want to use LIKE it's probably the only way to do it. If you want to use equals (=) on the other hand, you could do what you're trying to do with the current query, but it changes the behavior of the search.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Hi avdhut.k,

    Please replace AND with OR and your query will work 🙂

  • Hi Everyone,

    Thanks a Lot,

    Its Work for me.

    Thanks Again!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply