Tag: QUOTENAME in SQL Server


QUOTENAME function returns a unicode string with bracket by default.

Let us look at a simple example as below:

Select db_name(),quotename(db_name())


I personally observed many people are using this function for enclosing the db name or schema name or server name with brackets. This makes life easier in multiple occasions for me.

But, there are other ways that you can use this function to replace other characters as well.

The syntax is QUOTENAME(string, quote_char). There are some set of quote_char which are allowed to use as below in the screenshot.

Select db_name(),quotename(db_name())
Select Quotename(db_name(),'''') 
Select Quotename(db_name(),'"') 
Select Quotename(db_name(),'[')
Select Quotename(db_name(),'(')  
Select Quotename(db_name(),'<') 
Select Quotename(db_name(),'{') 



  1. If the string is having more than 128 characters, then QUOTENAME will be returning NULL value.

I’d like to grow my readership. If you enjoyed this blog post, please share it with your friends!