Skip to content

Latest commit

 

History

History
100 lines (77 loc) · 4.07 KB

File metadata and controls

100 lines (77 loc) · 4.07 KB
title QUOTENAME (Transact-SQL)
description QUOTENAME (Transact-SQL)
author MikeRayMSFT
ms.author mikeray
ms.date 03/14/2017
ms.service sql
ms.subservice t-sql
ms.topic reference
ms.custom
ignite-2025
f1_keywords
QUOTENAME_TSQL
QUOTENAME
helpviewer_keywords
delimited identifiers [SQL Server]
input strings [SQL Server]
Unicode [SQL Server], delimited identifiers
QUOTENAME function
valid identifiers [SQL Server]
dev_langs
TSQL
monikerRange >=aps-pdw-2016 || =azuresqldb-current || =azure-sqldw-latest || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric || =fabric-sqldb

QUOTENAME (Transact-SQL)

[!INCLUDE sql-asdb-asdbmi-asa-pdw-fabricse-fabricdw-fabricsqldb]

Returns a Unicode string with the delimiters added to make the input string a valid [!INCLUDEssNoVersion] delimited identifier.

:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions

Syntax

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

Arguments

'character_string'
Is 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'
Is a one-character string to use as the delimiter. 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 ( ` ). NULL returns if an unacceptable character is supplied. If quote_character is not 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 [!INCLUDEssNoVersion] delimited identifier.

SELECT QUOTENAME('abc[]def');

[!INCLUDEssResult]

[abc[]]def]
  
(1 row(s) affected)  

Notice that 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 NVARCHAR(255)='user''s "custom" name'
DECLARE @sql NVARCHAR(MAX) = 'SELECT FirstName AS ' + QUOTENAME(@columnName) + ' FROM dbo.DimCustomer'

EXEC sp_executesql @sql

Examples: [!INCLUDEssazuresynapse-md] and [!INCLUDEssPDW]

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

SELECT QUOTENAME('abc def');   

[!INCLUDEssResult]

[abc def]  
  
(1 row(s) affected)  

See Also

PARSENAME (Transact-SQL)
CONCAT (Transact-SQL)
CONCAT_WS (Transact-SQL)
FORMATMESSAGE (Transact-SQL)
REPLACE (Transact-SQL)
REVERSE (Transact-SQL)
STRING_AGG (Transact-SQL)
STRING_ESCAPE (Transact-SQL)
STUFF (Transact-SQL)
TRANSLATE (Transact-SQL)