T-SQL Tutorial T-SQL Advanced Database Management T-SQL References

T-SQL QUOTENAME() Function



The T-SQL (Transact-SQL) QUOTENAME() function returns a Unicode string with the delimiters added to make the input string a valid SQL Server delimited identifier.

Syntax

QUOTENAME('character_string' [ , 'quote_character' ])

Parameters

character_string Required. Specify a string of Unicode character data. It should be limited to 128 characters. If it is greater than 128 characters then the function returns NULL.
quote_character

Optional. Specify a one-character string to use as the delimiter. It can be a single quotation mark ( ' ), a left or right bracket ( [] ), a double quotation mark ( " ), a left or right parenthesis ( () ), a greater than or less than sign ( >< ), a left or right brace ( {} ) or a backtick ( ` ).

By default, brackets are used. The function returns NULL if an unacceptable character is supplied.

Return Value

Returns a Unicode string with the delimiters added.

Example 1:

The example below shows the usage of QUOTENAME() function.

SELECT QUOTENAME('abc def');
Result: [abc def]

SELECT QUOTENAME('abcdef', '()');
Result: (abcdef)

SELECT QUOTENAME('abc[]def');
Result: [abc[]]def]

❮ T-SQL Functions