SQL uses Unicode N in a stored procedure with a variable

I have the following stored procedure, I'm looking for the correct syntax, so I can reproduce the value "Comments" in the column "Comments", where "N" at the end of the line is the value for Unicode. I need to save the meaning of the characters in Russia.

So, at the moment, the meaning of the comments is passed as such

@comments

I want to do

N @ comments but not working

ALTER PROCEDURE [dbo].[spInsertContactUs]
(
@title VARCHAR(20) = default,
@forename VARCHAR(100) = default,
@surname VARCHAR(100) = default,
@gender VARCHAR(50) = default,
@address1 VARCHAR(100) = default,
@address2 VARCHAR(100) = default,
@city VARCHAR(50) = default,
@county VARCHAR(50) = default,
@country INT = default,
@zipcode VARCHAR(50) = default,
@email VARCHAR(200) = default,
@comments NVARCHAR(MAX) = default,
@mailinglist BIT = default,
@address3 VARCHAR(100) = default,
@dateOfBirth datetime = default
)
AS
SET NOCOUNT ON

INSERT INTO tblContactUs (
dateAdded,
title,
forename,
surname,
gender,
address1,
address2,
city,
county,
country,
zipcode,
email,
comments,
mailinglist,
address3,
dateOfBirth)
VALUES (
getdate(),
@title,
@forename,
@surname,
@gender,
@address1,
@address2,
@city,
@county,
@country,
@zipcode,
@email,
@comments,
@mailinglist,
@address3,
@dateOfBirth
)

SET NOCOUNT OFF
RETURN

;

+3
source share
3 answers

Use the data type Nvarcharin the table fields and stored procs parameters.

ADDED

See this link , maybe this will help you.

+3
source

. :

Command.Parameters.Add("@prc", SqlDbType.NVarChar).Value = strPrc; 

SqlDbType NVarChar. Nvarchar .

0
declare @a nvarchar(50)
set @a =N'تست'

exec('INSERT INTO [dbo].[tblP] ([productVal],[name],[month])  VALUES ( 9, '+'N'''+@a+''',1)')
INSERT INTO [dbo].[tblP] ([productVal],[year],[month])  VALUES ( 9, N'تست',1)
-1
source

Source: https://habr.com/ru/post/1759532/


All Articles