943,614 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Marked Solved
  • Views: 6138
  • MS SQL RSS
May 8th, 2008
0

WildCard search in SQL Server 2005?

Expand Post »
I have a table which have person's name as Prefix, firstname, lastname, address as three
different columns.
I want to get all records when fire a query like

SELECT * from Persons where name= 'abcd'

I want such query which can search in all three columns, it means abcd can be in
Prefix, firstname or lastname column.

Actually I have a page in which there are some text boxes which accepts some inputs and
based on that inputs displays matching records in GridView.

Suppose someone entered 'Ind', so my query should find records in all three columns of name.

And if someone entered record in first text box say name and nothing is entered in address text box, then
the records matching with that name with all addresses should get displayed.


How can I do that?

Thanks in advance,
Reputation Points: 10
Solved Threads: 0
Junior Poster
bhavna_816 is offline Offline
116 posts
since Sep 2006
May 8th, 2008
0

Re: WildCard search in SQL Server 2005?

I have joined three columns as
MS SQL Syntax (Toggle Plain Text)
  1. SELECT (Prefix+' '+firstname+' '+lastname) FROM Persons
Reputation Points: 10
Solved Threads: 0
Junior Poster
bhavna_816 is offline Offline
116 posts
since Sep 2006
May 9th, 2008
0

Re: WildCard search in SQL Server 2005?

sql Syntax (Toggle Plain Text)
  1. SELECT * FROM persons WHERE (prefix LIKE '%'+@input+'%'
  2. OR
  3. firstname LIKE '%'+@input+'%'
  4. OR
  5. lastname LIKE '%'+@input+'%')
  6. AND address LIKE '%'+@addressinput+'%'
Last edited by campkev; May 9th, 2008 at 3:45 pm.
Reputation Points: 14
Solved Threads: 19
Posting Pro in Training
campkev is offline Offline
484 posts
since Jul 2005
May 14th, 2008
0

Re: WildCard search in SQL Server 2005?

Thank you very much this has been a very useful post as i was having exactly the same problems.

Thanks again

Matt
Reputation Points: 10
Solved Threads: 2
Light Poster
gunso4050 is offline Offline
32 posts
since Nov 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MS SQL Forum Timeline: using joining 'line' tables
Next Thread in MS SQL Forum Timeline: String Search in Mobile Applications





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC