Warm tip: This article is reproduced from stackoverflow.com, please click
sql sql-server

Use of unicode N prefix with quote escape

发布于 2020-03-29 21:01:19

I have a problem where I need to store the select statement as a value in a field in database for the web service to execute it later and show the result in a different application.

When I update the value with the select statement in the table escaping the single quotes I loose the unicode N prefix functionality.

Example:

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

When executing the saved SQL statement, the column name is returned as 'I' not 'Ī' Is there any special way to escape single quotes when using N prefix?

Questioner
Toms F
Viewed
19
Kemal AL GAZZAH 2020-01-31 18:35

Add N to the head of 'select No as N''Ī'' from table'

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