SQL Server/T-SQL Tutorial/String Functions/QUOTENAME
QUOTENAME function
5> USE Northwind;
6> DECLARE @db AS NVARCHAR(258);
7> SET @db = QUOTENAME(N"pubs");
8> EXEC(N"USE " + @db + N" SELECT DB_NAME();");
9>
10> GO
QUOTENAME takes a character string and turns it in to a valid SQL Server identifier, which can be used as a name for a SQL
Server object, such as a table, column, etc.
7> SELECT QUOTENAME("[bad] table name")
8> GO
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------
[[bad]] table name]
(1 rows affected)