STRING_ESCAPE (Transact-SQL)

**APPLIES TO:** ![yes](media/yes.png)SQL Server (starting with 2016) ![yes](media/yes.png)Azure SQL Database ![no](media/no.png)Azure SQL Data Warehouse ![no](media/no.png)Parallel Data Warehouse

Escapes special characters in texts and returns text with escaped characters. STRING_ESCAPE is a deterministic function.

Topic link icon Transact-SQL Syntax Conventions

Syntax

STRING_ESCAPE( text , type )  

Arguments

text
Is a nvarcharexpression expression representing the object that should be escaped.

type
Escaping rules that will be applied. Currently the value supported is 'json'.

Return Types

nvarchar(max) text with escaped special and control characters. Currently STRING_ESCAPE can only escape JSON special characters shown in the following tables.

Special character Encoded sequence
Quotation mark (") \"
Reverse solidus (\) \|
Solidus (/) \/
Backspace
Form feed
New line
Carriage return
Horizontal tab
Control character Encoded sequence
|CHAR(0)|