温馨提示:本文翻译自stackoverflow.com,查看原文请点击:sql - Use of unicode N prefix with quote escape
sql sql-server

sql - Unicode N前缀与引号转义的使用

发布于 2020-03-29 21:46:21

我有一个问题,我需要将select语句作为值存储在数据库中的字段中,以供Web服务稍后执行并在其他应用程序中显示结果。

当我使用表中的select语句转义单引号来更新值时,我松开了unicode N前缀功能。

例:

update table
set sqlstatement = 'select No as N''Ī'' from table'
where ID = 1

执行保存的SQL语句时,列名返回为“ I”而不是“Ī”。使用N前缀时,是否有任何特殊方法可以转义单引号

查看更多

提问者
Toms F
被浏览
16
Kemal AL GAZZAH 2020-01-31 18:35

在“从表中选择否作为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