how to insert unicode text to SQL Server from query window
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.
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..
The following should work, N
indicates a "Unicode constant string" in MSSQL:
INSERT INTO tForeignLanguage ([Name]) VALUES (N'Араб')
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.