0

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,

3
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by gunso4050
0

I have joined three columns as

SELECT (Prefix+' '+firstname+' '+lastname) from Persons
0
select * from persons where (prefix like '%'+@input+'%'
or 
firstname like '%'+@input+'%'
or
lastname like '%'+@input+'%')
and address like '%'+@addressinput+'%'
0

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

Thanks again

Matt :) :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.