sqlsql-serverescapingliterals

SQL literal escape character


What is the escape character for MS-SQL-Server

WHERE field1 LIKE 'I'm'

Note the middle quotation is invalid, what is SQL's literal character, like / in C#


Solution

  • Use double ' to escape it in SQL-Server

    WHERE field1 LIKE 'I''m'
    

    In other DB engines like MySQL using backslash works too

    WHERE field1 LIKE 'I\'m'
    

    SQLFiddle demo