14

I have a table on my MS-SQL-Server 2008R2 that itself has an nvarchar(50) field.

Now when i insert a value using the Server Management Studio like

INSERT INTO INFORMATIONS(SOME_TEXT) VALUES('finančné služby')

and i immediately select the value

SELECT SOME_TEXT FROM INFORMATIONS

i get

financné služby

So the čdoes get converted into a plain c while the ž is handled just fine.

What am I missing here?

The collation is set to Latin1_General_CI_AS if that is of any help.

BigBlackDog
  • 544
  • 1
  • 6
  • 19

3 Answers3

31

Prefix your values with N while inserting.

INSERT INTO INFORMATIONS(SOME_TEXT) VALUES(N'finančné služby')

CHECK SQL FIDDLE DEMO

Mudassir Hasan
  • 28,083
  • 20
  • 99
  • 133
  • When I try this I get the same thing, it changes the characters (on sql 2012) – M T Head Sep 20 '16 at 18:31
  • 4
    This works, but why? I'd like to get some explanation – Nikola Sep 21 '17 at 12:49
  • @Nikola I think N means native, therefore supporting those characters. – Numan Karaaslan May 26 '20 at 12:55
  • In the 2008R2 version of the server, [`char` and `varchar`](https://learn.microsoft.com/en-us/previous-versions/sql/sql-server-2008-r2/ms176089(v=sql.105)) hold non-unicode characters, while [`nchar` and `nvarchar`](https://learn.microsoft.com/en-us/previous-versions/sql/sql-server-2008-r2/ms186939(v=sql.105)) hold unicode characters. The 'N' character before a string states that it must be treated as unicode characters. In newest version of MSSQL, check documentation, because the four type of fields have changed behaviour. – Dym Oct 08 '21 at 07:03
  • 1
    Man su saved my life. I was struggling with python insert on SQL Server 2008R2. Thank you! – Arunas V. Mar 09 '22 at 09:20
1

If you are working with stored procedure then give type 'Nvarchar' instead of Varchar of that particular filed on that you will store UTF-8 characters

Vrunda Savaliya
  • 180
  • 1
  • 5
0

Add N with the with string

  insert into Item_Registration ([fırstlan_arabic],[second_turkish])values(N'قهوة شوكو',N'قهوة شوكو')

enter image description here

ıf you are usıng C# or vb.net and Sqlcommand for inserting utf character you can use SqlDbtype.NText data type

CMD = New SqlCommand(cb)
 CMD.Parameters.AddWithValue("@d11", SqlDbType.NText).Value =
                    If(txt_name_secondlan.Text = "", "''", txt_name_secondlan.Text)
lava
  • 6,020
  • 2
  • 31
  • 28