I am going to continue my series of very short articles or tidbits on Transaction SQL string functions. I will exploring the QUOTENAME() function today. The QUOTENAME() function takes a input of type sysname, nvarchar(128) and returns a string, nvarchar(258) with quote characters at front and end of the string. A optional string can be specified to redefine the default quote character for TSQL. The following example creates a table name in the adventure works database from two variables.
1 2 3 4 5 6 |
-- Set local variables declare @var_schema sysname = 'SalesLT'; declare @var_name sysname = 'Product'; -- Make table name from ADW select quotename(@var_schema) + '.' + quotename(@var_name) as my_name; |
1 2 3 4 5 |
output: my_name ------------------- [SalesLT].[Product] |
The default quote characters [] can be changed by…