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 |
|
CybIRO
Starting Member
3 Posts |
Posted - 2004-05-18 : 20:22:17
|
Hi.I'm using a query to a table that contains names and lastnames.For example:"Nancy O'Neal"I need to make a query that accepts the ['] character in order tobe able to search "select * from tUsers where tUse_last_name like 'O'Neal'"Obviously, that query will return an error. I thought that maybe I could do it by using the ESCAPE clause... but It didn't work!Does anybody has any idea?Thanx a lot. |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2004-05-18 : 20:32:53
|
| DECLARE @weirdstuff TABLE( weirdstuff VARCHAR(55))INSERT @weirdstuff(weirdstuff) SELECT 'duh''hello' UNION ALL SELECT 'hello'SELECT weirdstuff FROM @weirdstuff WHERE weirdstuff LIKE '%''%'MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
CybIRO
Starting Member
3 Posts |
Posted - 2004-05-18 : 20:42:15
|
Thank You... I should have known that It would be that easy!!!thanks!select * from tUsers where tUse_last_name like 'O''Neal'Now I just need to replace the ['] for [''] and that's it.Cheers! |
 |
|
|
mahesh
Starting Member
6 Posts |
Posted - 2004-05-19 : 10:19:11
|
| select replace(fieldname,char(39),char(39)+char(39)) from tnameYou want to replace ['] by ['']Mahesh ParanjpeSQL DBA |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-05-19 : 10:24:33
|
| select replace(fieldname,'''','''''') from tname==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|