Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String comparison

Status
Not open for further replies.

emozley

Technical User
Joined
Jan 14, 2003
Messages
769
Location
GB
Hi,

I have written a telephone directory app that has a search box. The idea is you can search for a name and it will compare what you've typed in against first name and surname in the database.

I want to make it so if you search for "Ed Mozley" you still get a match:

This query works in Access but not in SQL - what is the equivalent please?

"OR bwbnet_Users.FirstName & ' ' & bwbnet_Users.Surname LIKE '" & search & "%' "

Thanks very much

Ed

 
Replace the first 2 & with +

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
You better parse the passed string into 2 parts, e.g.
Code:
declare @SearchStr varchar(max) = 'Ed Mozley'

declare @FirstName varchar(100), @LastName varchar(100)

select @FirstName = substring(@SearchStr,1, 
charindex(' ',@SearchStr + ' ') - 1), @LastName =
substring(@SearchStr, charindex(' ',@SearchStr + ' ') + 1,
len(@SearchString))

select * from myTable where FirstName = @FirstName and SurName = @LastName

---
from the top of my head.


PluralSight Learning Library
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top