sql server: need to escape [?

后端 未结 3 1979
无人及你
无人及你 2020-12-19 06:11

I need to escape [ in an sql query for SQL Server

select * from sometable where name like \'[something]\';

I actually am looking for a [ be

3条回答
  •  醉梦人生
    2020-12-19 06:33

    Embed the [ in []

    declare @T table
    (
      name varchar(20)
    )
    
    insert into @T values
    ('abc'),
    ('[abc')
    
    select *
    from @T 
    where name like '[[]a%'
    

    Result:

    name
    --------------------
    [abc
    

    Have a look here at what you can do in the like expression. LIKE (Transact-SQL)

提交回复
热议问题