Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Query to Search the Data Expand / Collapse
Author
Message
Posted Thursday, May 9, 2013 3:03 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Saturday, September 27, 2014 12:50 AM
Points: 135, Visits: 260
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!
Post #1450944
Posted Thursday, May 9, 2013 3:11 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 7:33 AM
Points: 2,873, Visits: 5,190
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!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1450949
Posted Thursday, May 9, 2013 3:51 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 5:13 AM
Points: 14,031, Visits: 28,405
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
The Scary DBA
Author of: SQL Server Query Performance Tuning
SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1450966
Posted Thursday, May 9, 2013 3:57 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, July 15, 2013 6:32 AM
Points: 34, Visits: 70
Hi avdhut.k,

Please replace AND with OR and your query will work :)
Post #1450970
Posted Thursday, May 9, 2013 4:07 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Saturday, September 27, 2014 12:50 AM
Points: 135, Visits: 260
Hi Everyone,

Thanks a Lot,

Its Work for me.



Thanks Again!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Post #1450983
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse