简体   繁体   中英

ESCAPE SEQUENCE IN SQL SERVER

I have to do a where by clause on my table to find the exact string match in my table it works fine in the following scenario

declare @issuerName varchar(max)
set @issuerName = 'WIDEOPENWEST FINANCE, LLC'

select * 
from company 
where ParentName = @issuerName

but fails for the following query

declare @issuerName varchar(max)
set @issuerName = 'TOYS 'R' US, INC'

select * 
from company 
where ParentName = @issuerName

because of the single quotes.

Could someone let me know what it would be the best way to tackle it since single quotes can appear any where in the string? I tried adding single quotes around this variable but it doesn't work.

set @issuerName = ''TOYS 'R' US, INC''

You'd do this:

set @issuerName = 'TOYS ''R'' US, INC'

Putting the escaped ' within the string itself.

Further, if you need to change the escaped character as with a LIKE clause you may want to check out the ESCAPE keyword which lets you change the character used for the current query. Please see Using [] and ESCAPE clause in SQL Server LIKE query .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM