QUOTENAME

返回由分隔符包围的 Unicode 字符串,以使其成为有效的 SQL Server 分隔标识符。

参数:

  1. 字符串。一串 Unicode 数据,最多 128 个字符(sysname)。如果输入字符串超过 128 个字符,则函数返回 null
  2. 引用字符。可选。用作分隔符的单个字符。可以是单引号('或``),左支架或右支架({[(<>)]})或双引号(")。任何其他值都将返回 null。默认值为方括号。
SELECT QUOTENAME('what''s my name?')      -- Returns [what's my name?]

SELECT QUOTENAME('what''s my name?', '[') -- Returns [what's my name?]
SELECT QUOTENAME('what''s my name?', ']') -- Returns [what's my name?]

SELECT QUOTENAME('what''s my name?', '''') -- Returns 'what''s my name?'

SELECT QUOTENAME('what''s my name?', '"') -- Returns "what's my name?"

SELECT QUOTENAME('what''s my name?', ')') -- Returns (what's my name?)
SELECT QUOTENAME('what''s my name?', '(') -- Returns (what's my name?)

SELECT QUOTENAME('what''s my name?', '<') -- Returns <what's my name?>
SELECT QUOTENAME('what''s my name?', '>') -- Returns <what's my name?>

SELECT QUOTENAME('what''s my name?', '{') -- Returns {what's my name?}
SELECT QUOTENAME('what''s my name?', '}') -- Returns {what's my name?}

SELECT QUOTENAME('what''s my name?', '`') -- Returns `what's my name?`