现在的位置: 首页 > 综合 > 正文

给表名添加有效字符标识

2013年09月18日 ⁄ 综合 ⁄ 共 742字 ⁄ 字号 评论关闭

--Microsoft SQL Server 2005 - 9.00.1399.06
-- (Intel X86)   Oct 14 2005 00:33:37   Copyright (c) 1988-2005
-- Microsoft Corporation  Enterprise Edition on Windows NT 5.2 (Build 3790: Service Pack 2)
--select left('claro',2)整理于西安 2009-02-12 08:51:02.000

--给表名添加有效字符标识
--定义:
QUOTENAME  返回带有分隔符的 Unicode 字符串,分隔符的加入可使输入的字符串成为有效的 Microsoft SQL Server 2005 分隔标识符。
--简单的说给字符串前后(默认[])添加标识。

--语法:
QUOTENAME ( 'character_string' [ , 'quote_character' ] )
--'character_string'  Unicode 字符数据构成的字符串。character_string 是 sysname 值。
--'quote_character'  用作分隔符的单字符字符串。可以是单引号 (')、左方括号或右方括号 ([ ]) 或者英文双引号 (")。

--返回类型 nvarchar(258)
--example:
select top 1 N'select top 10 * from '+QUOTENAME(name) from sys.sysobjects where type='u'
--select top 10 * from [tableA]
select top 1 N'select top 10 * from '+(name) from sys.sysobjects where type='u'
--select top 10 * from tableA

抱歉!评论已关闭.