Sql query with special characters - how to handle?

前端 未结 5 1013
南方客
南方客 2021-01-06 16:53

I\'ve few emp names like

  1. john,1
  2. devil\'s
  3. corn

something like this

Now when

5条回答
  •  执念已碎
    2021-01-06 17:28

    This assumes you have 3 discrete names in your example string

    Exact match. you need to double up quotes.

    select * from emp where
    empname IN ('john,1' , 'devil''s', 'corn')
    

    You can't LIKE/IN in SQL Server too.

    select * from emp where
      empname like '%john,1%'
      OR
      empname like '%devil''s%'
      OR
      empname like '%corn%'
    

提交回复
热议问题