Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert greek characters into sqlserver table

Tags:

sql-server

I have a simple insert, but with greek characters

INSERT INTO tmp (fname) VALUES ('ΚΩΝΣΤΑΝΤΙΝΟΣ')

I have tried creating the table in two ways:

create table tmp (fname varchar(40))

and

create table tmp (fname nvarchar(40))

When I then select the data:

select * from tmp

I get:

?O?S???????S

I'm using:

Microsoft SQL Server 2005 - 9.00.4060.00 (Intel X86) 
    Mar 17 2011 13:20:38 
    Copyright (c) 1988-2005 Microsoft Corporation
    Standard Edition on Windows NT 5.2 (Build 3790: Service Pack 2)

and

Microsoft SQL Server 2012 (SP1) - 11.0.3000.0 (X64) 
    Oct 19 2012 13:38:57 
    Copyright (c) Microsoft Corporation
    Standard Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) (Hypervisor)

it does the same in both.

I'm using:

Microsoft SQL Server Management Studio  11.0.2100.60

to create the table and insert the data etc.

How do I get Greek characters to store correctly or if they are stored correctly to display correctly when I select them?

like image 958
Graham Avatar asked Sep 21 '15 13:09

Graham


1 Answers

Try to use prefix Unicode character string:

create table tmp (fname nvarchar(40))
INSERT INTO tmp (fname) VALUES (N'ΚΩΝΣΤΑΝΤΙΝΟΣ')

Also there may be a problem with collation of the columns, please set

create table tmp (fname nvarchar(40) COLLATE SQL_Latin1_General_CP1253_CI_AI)

From MSDN:

Prefix Unicode character string constants with the letter N. Without the N prefix, the string is converted to the default code page of the database. This default code page may not recognize certain characters.

like image 130
Roman Marusyk Avatar answered Oct 13 '22 21:10

Roman Marusyk