| title | QUOTENAME (Transact-SQL) | |||||
|---|---|---|---|---|---|---|
| description | QUOTENAME returns a Unicode string with the delimiters added to make the input string a valid SQL Engine delimited identifier. | |||||
| author | MikeRayMSFT | |||||
| ms.author | mikeray | |||||
| ms.reviewer | randolphwest | |||||
| ms.date | 04/08/2026 | |||||
| ms.service | sql | |||||
| ms.subservice | t-sql | |||||
| ms.topic | reference | |||||
| ms.custom |
|
|||||
| f1_keywords |
|
|||||
| helpviewer_keywords |
|
|||||
| dev_langs |
|
|||||
| monikerRange | >=aps-pdw-2016 || =azuresqldb-current || =azure-sqldw-latest || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric || =fabric-sqldb |
[!INCLUDE sql-asdb-asdbmi-asa-pdw-fabricse-fabricdw-fabricsqldb]
Returns a Unicode string with the delimiters added to make the input string a valid [!INCLUDE ssNoVersion] delimited identifier.
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions
QUOTENAME ( 'character_string' [ , 'quote_character' ] )
A string of Unicode character data. character_string is sysname and is limited to 128 characters. Inputs greater than 128 characters return NULL.
A one-character string to use as the delimiter. Can be a single quotation mark ('), a left or right bracket ([ or ]), a double quotation mark ("), a left or right parenthesis (( or )), a greater than or less than sign (> or <), a left or right brace ({ or }) or a backtick (```).
If you provide an unacceptable quote character, NULL is returned. If quote_character isn't specified, brackets are used.
nvarchar(258)
The following example takes the character string abc[]def and uses the [ and ] characters to create a valid [!INCLUDE ssNoVersion] delimited identifier.
SELECT QUOTENAME('abc[]def');[!INCLUDE ssResult]
[abc[]]def]
The right bracket in the string abc[]def is doubled to indicate an escape character.
The following example prepares a quoted string to use in naming a column.
DECLARE @columnName AS NVARCHAR (255) = 'user''s "custom" name';
DECLARE @sql AS NVARCHAR (MAX) = 'SELECT FirstName AS ' + QUOTENAME(@columnName) + ' FROM dbo.DimCustomer';
EXECUTE sp_executesql @sql;The following example takes the character string abc def and uses the [ and ] characters to create a valid [!INCLUDE ssNoVersion] delimited identifier.
SELECT QUOTENAME('abc def');[!INCLUDE ssResult]
[abc def]