Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
littlewing
Starting Member
33 Posts |
Posted - 2006-06-22 : 09:10:16
|
| Hi I have a simple lookup of firstname and lastname using LIKE. SELECT * from Customers WHERE FirstName LIKE '%' + @Key + '%' OR LastName LIKE '%' + @Key + '%'Sample Dataid firstname lastname1 John Smith2 Barb Wire3 Bob GreenAll is well until someone submits the string 'John Smith' - then the search returns 0 results. Is there a way to "concatenate" the firstname and lastname columns into a "virtual" column that LIKE can search against and return 1 record when @key = 'John Smith'? Thanks very much.LW |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-06-22 : 09:15:53
|
| TrySELECT * from Customers WHERE FirstName+ ' '+ LastName LIKE '%' + @Key + '%'MadhivananFailing to plan is Planning to fail |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-06-22 : 09:16:31
|
| Yes.Make virtual column formula asLTRIM(RTRIM(LTRIM(RTRIM(FirstName)) + ' ' + LTRIM(RTRIM(LastName))))But then you will face problem with "Smith, John".Peter LarssonHelsingborg, Sweden |
 |
|
|
cvraghu
Posting Yak Master
187 Posts |
Posted - 2006-06-22 : 14:29:43
|
| It would be better to get seperate search strings for First name and last name from user. SELECT * from Customers WHERE FirstName LIKE '%' + @FKey + '%' OR LastName LIKE '%' + @LKey + '%' |
 |
|
|
|
|
|