WildCard search in SQL Server 2005?

Please support our MS SQL advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Sep 2006
Posts: 116
Reputation: bhavna_816 is an unknown quantity at this point 
Solved Threads: 0
bhavna_816 bhavna_816 is offline Offline
Junior Poster

WildCard search in SQL Server 2005?

 
0
  #1
May 8th, 2008
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,
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 116
Reputation: bhavna_816 is an unknown quantity at this point 
Solved Threads: 0
bhavna_816 bhavna_816 is offline Offline
Junior Poster

Re: WildCard search in SQL Server 2005?

 
0
  #2
May 8th, 2008
I have joined three columns as
  1. SELECT (Prefix+' '+firstname+' '+lastname) FROM Persons
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 483
Reputation: campkev is an unknown quantity at this point 
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: WildCard search in SQL Server 2005?

 
0
  #3
May 9th, 2008
  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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 31
Reputation: gunso4050 is an unknown quantity at this point 
Solved Threads: 2
gunso4050 gunso4050 is offline Offline
Light Poster

Re: WildCard search in SQL Server 2005?

 
0
  #4
May 14th, 2008
Thank you very much this has been a very useful post as i was having exactly the same problems.

Thanks again

Matt
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the MS SQL Forum
Thread Tools Search this Thread



Tag cloud for MS SQL
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC