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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 How can I seek the character ['] in a query?

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 to
be 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 '%''%'

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

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!
Go to Top of Page

mahesh
Starting Member

6 Posts

Posted - 2004-05-19 : 10:19:11
select replace(fieldname,char(39),char(39)+char(39)) from tname
You want to replace ['] by ['']

Mahesh Paranjpe
SQL DBA
Go to Top of Page

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.
Go to Top of Page
   

- Advertisement -