Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

QUOTENAME (Transact-SQL)

Applies to: 👁 Image
SQL Server 👁 Image
Azure SQL Database 👁 Image
Azure SQL Managed Instance 👁 Image
Azure Synapse Analytics 👁 Image
Analytics Platform System (PDW) 👁 Image
SQL analytics endpoint in Microsoft Fabric 👁 Image
Warehouse in Microsoft Fabric 👁 Image
SQL database in Microsoft Fabric

Returns a Unicode string with the delimiters added to make the input string a valid SQL Server delimited identifier.

👁 Image
Transact-SQL syntax conventions

Syntax

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

Arguments

'character_string'

A string of Unicode character data. character_string is sysname and is limited to 128 characters. Inputs greater than 128 characters return NULL.

'quote_character'

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.

Return types

nvarchar(258)

Examples

The following example takes the character string abc[]def and uses the [ and ] characters to create a valid SQL Server delimited identifier.

SELECT QUOTENAME('abc[]def');

Here's the result set.

[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;

Examples: Azure Synapse Analytics and Analytics Platform System (PDW)

The following example takes the character string abc def and uses the [ and ] characters to create a valid SQL Server delimited identifier.

SELECT QUOTENAME('abc def');

Here's the result set.

[abc def]

Related content


Feedback

Was this page helpful?

Additional resources