我有一个问题,我需要将select语句作为值存储在数据库中的字段中,以供Web服务稍后执行并在其他应用程序中显示结果。
当我使用表中的select语句转义单引号来更新值时,我松开了unicode N
前缀功能。
例:
update table
set sqlstatement = 'select No as N''Ī'' from table'
where ID = 1
执行保存的SQL语句时,列名返回为“ I”而不是“Ī”。使用N
前缀时,是否有任何特殊方法可以转义单引号?
在“从表中选择否作为N''Ī''的开头添加N
declare @table as table(id int identity(1,1),sqlstatement nvarchar(100))
insert into @table values('select No as N''Ī'' from table')
--before
select sqlstatement from @table where Id=1
declare @sqlstatement as nvarchar(100)
update @table
set sqlstatement = N'select No as N''Ī'' from table'
where ID = 1
--After
select sqlstatement from @table where Id=1