Using Quotename function in SQL 2008

In this article I describe how to store strings in various formats in SQL Server.
  • 6349

 Introduction

Quotename() is a SQL Server String function. Quotename function adds the square brackets to the beginning and end of the string. this function is helpful  when database object names have space between them. Quotename() function can take string up to 128 characters as input. So lets take a example to implement Quotename() function:

Syntax:

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

where,

character_string- specifies the string in which delimiter is to be added.

quote_character- specifies type of delimiter which includes- single quote ('), double quote (") and square bracket ([]). If no delimiter is specified then it will take square bracket as delimiter.

Example:

Lets tale some practical example of QUOTENAME() function:

1.  Using Quotename function with default value square brackets.

select quotename('Management Studio')

Output:

quotename_function-with-DefaultValue.jpg
 

2. Using Quotename function with single quote.

select quotename('Management Studio', '''')

Output:

quotename_function-with-singleQuote.jpg
 

3. Using Quotename function with double quote.

select quotename('Management Studio', '"')

Output:

quotename_function-with-doubleQuote.jpg


Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.