Software development stuff.

2007-06-18

How to escape the % (Percent) sign in a LİKE query T-SQL

If you need to search the '%' sign in Transact SQL, cehcvk out the reference page for the LIKE (T-SQL):

USE pubs

GO

SELECT notes

FROM titles

WHERE notes LIKE '50%% off when 100 or more copies are purchased'

ESCAPE '%'

GO

Etiquetas:

1 Comments:

Blogger J. Divis said...

Gracias,

This fix was very helpful. As an extra note a statement like:

....
and (cappa.ADDR_LINE1_TEXT like '%_%%' OR cappa.ADDR_LINE2_TEXT like '%_%%')

ESCAPE '_'

will fail. You have to escape the character directly after the string with the escape character in it like:

and (cappa.ADDR_LINE1_TEXT like '%_%%' ESCAPE '_' OR cappa.ADDR_LINE2_TEXT like '%_%%' ESCAPE '_' OR cappa.ADDR_LINE3_TEXT like '%_%%' ESCAPE '_' OR cappa.ADDR_LINE4_TEXT like '%_%%' ESCAPE '_')

18:28

 

Enviar um comentário

<< Home