Contents

1 quotename() 伎蠍
2 蠏谿朱..


1 quotename() 伎蠍 #

貎朱Μ襯 燕る慨覃 一危 覦 襷 願 . 殊語 貎朱Μ覓語 燕螻 覲企 . 企蟆 一危 覦 蟆曙磯 quotename() 伎 SQL 燕覃 譬 蟆 SQL 焔覩襦 れ 蟆企.

declare @sql nvarchar(255)
set @sql = 
	'select * from sys.objects where name like ' + 
	quotename('%', '''') + '+' +
	quotename('sysdiagrams', '''') + '+' +
	quotename('%', '''')
print @sql
exec(@sql)

--select * from sys.objects where name like '%'+'sysdiagrams'+'%'

2 蠏谿朱.. #

quotename() ルГ螳覲螳 2螳. 蟆 蠏谿朱 襯 襷る .

CREATE FUNCTION dbo.quotestring(@str nvarchar(1998)) RETURNS nvarchar(4000) AS
BEGIN
   DECLARE @ret nvarchar(4000),
                 @sq  char(1)
   SELECT  @sq = ''''
   SELECT  @ret = replace(@str, @sq, @sq + @sq)
   RETURN(@sq + @ret + @sq)
END