how to insert unicode text to SQL Server from query window

后端 未结 5 1201
旧巷少年郎
旧巷少年郎 2020-12-01 06:21

I\'m using the following code:

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

this value inserted like this \'????\'

How d

相关标签:
5条回答
  • 2020-12-01 06:34

    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.

    0 讨论(0)
  • 2020-12-01 06:43

    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 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
    

    Hope this helps..

    0 讨论(0)
  • 2020-12-01 06:48

    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();
    }
    
    0 讨论(0)
  • 2020-12-01 06:56

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

    INSERT INTO tForeignLanguage ([Name]) VALUES (N'Араб')
    
    0 讨论(0)
  • 2020-12-01 06:57

    The perfect solution with data type limitation:

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

    0 讨论(0)
提交回复
热议问题