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 synatx 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(),'''') -- ' character
Select Quotename(db_name(),'"') -- " character
Select Quotename(db_name(),'[') -- [ character
Select Quotename(db_name(),'{') -- { character
Select Quotename(db_name(),'(') -- ( character
Select Quotename(db_name(),'<') -- < character

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

One thought on “QUOTENAME() in SQL Server”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s