46

I'm using the following code:

INSERT INTO tForeignLanguage ([Name]) VALUES ('Араб')

This value inserted like this: '????'

How do I insert Unicode text from the SQL Server Management Studio query window?

5 Answers 5

114

The following should work, N indicates a "Unicode constant string" in MSSQL:

INSERT INTO tForeignLanguage ([Name]) VALUES (N'Араб')
Sign up to request clarification or add additional context in comments.

1 Comment

This works only when DataType of column in DB is nvarchar.
2

The perfect solution with data type limitation:

Basically, in SQL Server, Amharic text is not working properly when the column datatype is 'text'. Therefore to put Amharic text on a column with datatype text, first change the text datatype to 'nvarchar(MAX)' or just 'nvarchar' with any char length that SQL Server supported.

Comments

1

Thanks to Ian's answer, you can directly run this code from query window:

declare @FamilyName nvarchar(40)
set @FamilyName = N'嗄嗄嗄'

insert into table(LoginName, Password)  select @FamilyName as LoginName, 123 as Password

However, if you wish to perform the above insert through stored procedure, it's needed to attach N as a prefix:

CREATE PROCEDURE Example
    @FAMILY_NAME   NVARCHAR(40)
AS
BEGIN

    SET NOCOUNT ON;
    declare @query nvarchar(400);


    set @query  ='insert into table(LoginName, Password)  select N'''+ @FAMILY_NAME +''' as LoginName, 123 as Password';

    EXECUTE sp_executesql @query;
    
END

Comments

0

In my case, the task at hand was to update an SQL table which contains list of countries in two languages in which the local language (Amharic) column was null so executing the following works fine.

    Update [tableName] set [columnName] = N'አሜሪካ'

The N in N'አሜሪካ' is the key to put the string as it is in your specific column.

Comments

-1

Just make datatype NVarchar in database and following;

internal string InsertUpdate(classname obj)
{
    SqlParameter[] sqlparam = new SqlParameter[];
    sqlparam[] = new SqlParameter("@DESC1", SqlDbType.NVarChar);
    sqlparam[].Value = NullHandler.String(obj.DESC1);
    sqlparam[] = new SqlParameter("@DESC2", SqlDbType.NVarChar);
    sqlparam[].Value = NullHandler.String(obj.DESC2);
    obj.InsertUpdateTable("spname", "sp", sqlparam);
    if (sqlparam[].Value != DBNull.Value)
        return sqlparam[].Value.ToString();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.