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 2005 Forums
 Transact-SQL (2005)
 looking for ' inside a string

Author  Topic 

albertkohl
Aged Yak Warrior

740 Posts

Posted - 2007-11-20 : 18:49:00
how would i run something like this:

select * from zipinfo2 where county like "%'%"

i know i cant use the double quotes, and they would usually be single quotes, but i cant because i'm looking for a single quote.

any help would be great! i'm sure it's something dumb :o)

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-11-20 : 18:54:47
LIKE '%[']%'

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

albertkohl
Aged Yak Warrior

740 Posts

Posted - 2007-11-20 : 20:12:52
select * from zipinfo2 where county LIKE '%[']%'

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ']'.
Msg 105, Level 15, State 1, Line 1
Unclosed quotation mark after the character string ''.
Go to Top of Page

Haywood
Posting Yak Master

221 Posts

Posted - 2007-11-20 : 20:45:22
[code]
CREATE TABLE Foo (State varchar(10))

INSERT INTO Foo
VALUES ('Foo''Bar')

SELECT *
FROM Foo

SELECT *
FROM Foo
WHERE State LIKE '%''%'
[/code]
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-11-21 : 01:01:31
or

1 like '%'+char(39)+'%'
2 charindex('''',col)>0


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -