Link to home
Create AccountLog in
Avatar of jamesdean666
jamesdean666

asked on

SQL Server Select Statement with 2 Escape Clasuses

When i search a column in a table in my database, I get no results returned when I search for brackets ([]) even though some characters in the column contain brackets.  How do I write a sql select statement that will return two escape clauses for each square bracket ([]).  I know I can do this for the 'open' bracket:

select * from forms
where form_name like  '%[[]%'  

but how do i do it for both?
Avatar of HugoHiasl
HugoHiasl

You don't need to escape the closing bracket.

There are multiple ways:

SELECT columns FROM table WHERE
    column LIKE '%[[]SQL Server Driver]%'

or

SELECT columns FROM table WHERE
    column LIKE '%\[SQL Server Driver]%' ESCAPE '\'


Source: http://sqlserver2000.databases.aspfaq.com/how-do-i-search-for-special-characters-e-g-in-sql-server.html
SOLUTION
Avatar of Wim_Bl
Wim_Bl
Flag of Belgium image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of jamesdean666

ASKER

dang.. i can't get those to work.. to be clear.. the string does not necessarily contain both brackets.. it can have one, or both.
no matter what i try, I can't get it to return the 'closed' bracket (])..The open bracket is returning fine.  Can't get the closed bracket to return with string that contain both brackets and only the closed bracket.
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Thanks all, hoped to be fair with points - I hope you agree..