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 |
fkhundmi
Starting Member
2 Posts |
Posted - 2009-11-05 : 15:20:55
|
I created a proc that will return a list of applicants by lastname. I have a problem searching Applicants with last name that has apostrophe (Example O'Connor). I need to find those applicants:Below is my Search Code:if Rtrim(@FirstName) <> ''begin If(Len(@FirstName) < 30) and (CharIndex('%', @FirstName) = 0) and @FirstName != '' Set @FirstName = char(39) + @FirstName + '%' + char(39)end if Rtrim(@LastName) <> ''begin If(Len(@LastName) < 60) and (CharIndex('%', @LastName) = 0) and @LastName != '' Set @LastName = Char(39) + @LastName + '%' + char(39)end #At the end - --Now build dinamically the filter base on input parametersif Rtrim(@FirstName) <> '' select @Where = @Where + ' and a.FirstName like '+ Rtrim(@FirstName) if Rtrim(@LastName) <> '' select @Where = @Where + ' and a.LastName like '+ Rtrim(@LastName) |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2009-11-05 : 15:56:59
|
Obviously, you should test it first, but I think you just need to double up the single quotes, like: REPLACE(@FirstName, CHAR(39), CHAR(39) + CHAR(39)) |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|