May 9, 2013 at 3:03 am
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!
May 9, 2013 at 3:11 am
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/
May 9, 2013 at 3:51 am
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
May 9, 2013 at 3:57 am
Hi avdhut.k,
Please replace AND with OR and your query will work 🙂
May 9, 2013 at 4:07 am
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