SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Query to Search the Data


Query to Search the Data

Author
Message
avdhut.k
avdhut.k
Say Hey Kid
Say Hey Kid (673 reputation)Say Hey Kid (673 reputation)Say Hey Kid (673 reputation)Say Hey Kid (673 reputation)Say Hey Kid (673 reputation)Say Hey Kid (673 reputation)Say Hey Kid (673 reputation)Say Hey Kid (673 reputation)

Group: General Forum Members
Points: 673 Visits: 266
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!
Eugene Elutin
Eugene Elutin
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13084 Visits: 5478
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
Grant Fritchey
Grant Fritchey
SSC Guru
SSC Guru (101K reputation)SSC Guru (101K reputation)SSC Guru (101K reputation)SSC Guru (101K reputation)SSC Guru (101K reputation)SSC Guru (101K reputation)SSC Guru (101K reputation)SSC Guru (101K reputation)

Group: General Forum Members
Points: 101553 Visits: 33014
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 and SQL Server Execution Plans
Product Evangelist for Red Gate Software
suneet.mlvy
suneet.mlvy
SSC-Enthusiastic
SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)

Group: General Forum Members
Points: 166 Visits: 70
Hi avdhut.k,

Please replace AND with OR and your query will work Smile
avdhut.k
avdhut.k
Say Hey Kid
Say Hey Kid (673 reputation)Say Hey Kid (673 reputation)Say Hey Kid (673 reputation)Say Hey Kid (673 reputation)Say Hey Kid (673 reputation)Say Hey Kid (673 reputation)Say Hey Kid (673 reputation)Say Hey Kid (673 reputation)

Group: General Forum Members
Points: 673 Visits: 266
Hi Everyone,

Thanks a Lot,

Its Work for me.



Thanks Again!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search