Open In App

QUOTENAME() Function in SQL Server

Last Updated : 30 Dec, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

QUOTENAME() function :
This function in SQL Server is used to return a Unicode string with delimiters added in order to make the string a valid SQL Server delimited identifier.

Features :

  • This function is used to find a Unicode string with delimiters added.
  • This function accepts only strings and delimiters.
  • This function add delimiters by default if not specified.
  • This function always returns string along with delimiters.

Here, the string is limited to 128.

Syntax :

QUOTENAME(string, quote_char)

Parameter :
This method accepts two parameter as given below :

  • string: Specified string of Unicode character data which is limited to 128 characters.
  • quote_char : It is optional. It is a one-character string which is to be used as the delimiter. For example, it can be a single quotation mark i.e, ( ‘ ), or a left or right bracket i.e, ( [] ), or a double quotation mark i.e, ( ” ), or a left or right parenthesis i.e, ( () ), or a greater than or less than sign i.e, ( >< ), or a left or right brace i.e, ( {} ) or a backtick i.e, ( ` ). Moreover, if this parameter is not specified, the brackets are used by default.

Returns :
It returns a Unicode string with delimiters added in order to make the string a valid SQL Server delimited identifier.

Example-1 :
Getting the Unicode string of the string “xyz”.

SELECT QUOTENAME('xyz');

Output :

[xyz]

Here, the quote_char parameter is not defined but brackets are added to the output by default.

Example-2 :
Getting the Unicode string with parenthesis delimiters.

SELECT QUOTENAME('abc', '{}');

Output :

{abc}

Here, the delimiters are specified in the parameters so they are returned as output.

Example-3 :
Using QUOTENAME() function with a variable and getting the Unicode string of the specified string.

DECLARE @string VARCHAR(3);  
SET @string = '123';  
SELECT QUOTENAME(@string);

Output :

[123]

Example-4 :
Using QUOTENAME() function with a variable and getting the Unicode string of the specified string as well as delimiters.

DECLARE @string VARCHAR(4);
DECLARE @delimiter VARCHAR(2);
SET @string = 'jk12';
SET @delimiter = '()';
SELECT QUOTENAME(@string, @delimiter);

Output :

(jk12)

Example-5 :
Getting the Unicode string with greater than sign.

SELECT QUOTENAME('23', '>');

Output :

<23>

This delimiter only works with numbers.

Application :
This function is used to return the Unicode string with delimiters added to it in order to make the string a valid SQL Server delimited identifier.


Similar Reads

Configure SQL Jobs in SQL Server using T-SQL
In this article, we will learn how to configure SQL jobs in SQL Server using T-SQL. Also, we will discuss the parameters of SQL jobs in SQL Server using T-SQL in detail. Let's discuss it one by one. Introduction :SQL Server Agent is a component used for database task automation. For Example, If we need to perform index maintenance on Production ser
7 min read
SQL SERVER – Input and Output Parameter For Dynamic SQL
An Input Parameter can influence the subset of rows it returns from a select statement within it. A calling script can get the value of an output parameter. An aggregate function or any computational expression within the stored process can be used to determine the value of the output parameter. A parameter whose value is given into a stored proced
3 min read
SQL Server | Convert tables in T-SQL into XML
In this, we will focus on how tables will be converted in T-SQL into XML in SQL server. And you will be able to understand how you can convert it with the help of command. Let's discuss it one by one. Overview :XML (Extensible Markup Language) is a markup language similar to HTML which was designed to share information between different platforms.
2 min read
SQL SERVER | Bulk insert data from csv file using T-SQL command
In this article, we will cover bulk insert data from csv file using the T-SQL command in the SQL server. And will also cover the way is more useful and more convenient to perform such kind of operations. Let's discuss it one by one. Introduction :Sometimes there is a scenario when we have to perform bulk insert data from .csv files into SQL Server
3 min read
SQL - SELECT from Multiple Tables with MS SQL Server
In SQL we can retrieve data from multiple tables also by using SELECT with multiple tables which actually results in CROSS JOIN of all the tables. The resulting table occurring from CROSS JOIN of two contains all the row combinations of the 2nd table which is a Cartesian product of tables. If we consider table1 contains m rows and table2 contains n
3 min read
How to Execute SQL Server Stored Procedure in SQL Developer?
A stored procedure is a set of (T-SQL ) statements needed in times when we are having the repetitive usage of the same query. When there is a need to use a large query multiple times we can create a stored procedure once and execute the same wherever needed instead of writing the whole query again. In this article let us see how to execute SQL Serv
2 min read
SQL Query to Convert Rows to Columns in SQL Server
In this article we will see, how to convert Rows to Column in SQL Server. In a table where many columns have the have same data for many entries in the table, it is advisable to convert the rows to column. This will help to reduce the table and make the table more readable. For example, Suppose we have a table given below: NAMECOLLEGEROLL NUMBERSUB
2 min read
How to SQL Select from Stored Procedure using SQL Server?
There may be situations in SQL Server where you need to use a stored procedure to get data from a SQL query. For direct data selection from a stored procedure within a query, SQL Server offers options like OPENQUERY and OPENROWSET. The usual way is running the stored procedure independently and then querying the outcomes. The idea of utilizing SQL
3 min read
Difference between Structured Query Language (SQL) and Transact-SQL (T-SQL)
Structured Query Language (SQL): Structured Query Language (SQL) has a specific design motive for defining, accessing and changement of data. It is considered as non-procedural, In that case the important elements and its results are first specified without taking care of the how they are computed. It is implemented over the database which is drive
2 min read
SQL Server | STUFF() Function
There are situations when user want to change some portion of the data inserted. The reason may be because of human error or the change in data. For this purpose, stuff() function comes to action. STUFF() : In SQL Server, stuff() function is used to delete a sequence of given length of characters from the source string and inserting the given seque
1 min read
Article Tags :