![](/style/images/good.png)
![](/style/images/bad.png)
Does the SQL run a string problem with a national language character?
source link: https://www.codesd.com/item/does-the-sql-run-a-string-problem-with-a-national-language-character.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Does the SQL run a string problem with a national language character?
i have a simple sp in sql as bellow :
alter proc sptest(@val nvarchar(30))
as
select COUNT(*) from AAtable
where name = @val
as i call this sp with @val = 'مریم', it works well and returns value. but when i change it like this :
alter proc sptest(@val nvarchar(30))
as
declare @q nvarchar(max)
set @q = 'select COUNT(*) from AAtable where name = ' + @val
Execute(@q)
and call it with the same @val, it converts @val value to "?" and returns error. i should say that @val comes from a string parameter in c#. as i know .net convert string to nvarchar parameter form sql. anyway i can not add N before @val. and also i HAVE to make a string query and execute it so i can not change it to the first code too.
if i do this : set @q = 'select COUNT(*) from AAtable where name = N''' + @val + '''' it does not work too.
why execute string makes my nvarchar parameter to "?" !?
Add the N in front of your text, so it is an NVARCHAR literal, not a VARCHAR, like this: N'My Text'
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK