Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In my contact table, I'm getting ? symbols in LastName. How can I avoid that?

FirstName   MiddleName     LastName
Bjorn       Erik           N?ss
Gunn                       Gjos?ther
Oystein     Larsen         Indrev?r
Louise      Tulle          Pr?strud
share|improve this question
4  
Hi, Where do you see that output? What is the table definition? What is your query? – Tom V Mar 15 at 14:35

You need to ensure the LastName column is a Unicode type, for example nvarchar(30), and use the N prefix on any literal strings you use in insert/update/merge statements. (Alternatively, you could use a non-Unicode type with a code page that supports all the characters you need.)

SQL Server replaces characters it cannot convert with the ? symbol.

See nchar and nvarchar (Transact-SQL)

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.

The code page is determined by the collation. Taking SQL_Latin1_General_CP1251_CI_AS as an example:

SELECT FH.[description]
FROM sys.fn_helpcollations() AS FH
WHERE FH.name = N'SQL_Latin1_General_CP1251_CI_AS';

Output:

Latin1-General, case-insensitive, accent-sensitive, 
    kanatype-insensitive, width-insensitive for Unicode Data  
SQL Server Sort Order 106 on Code Page 1251 for non-Unicode Data

Code page 1251 (used for non-Unicode data in that collation) does not have the æ character, so:

SELECT 'Gjøsæther' COLLATE SQL_Latin1_General_CP1251_CI_AS;

Produces:

Gjos?ther

Notice that as well as the ?, the ø character was translated to o.

The question does not state which collation the instance/database/column is using, but it seems very likely it is the wrong one for your data.

More general information:

Data Types (Transact-SQL)
Collation and Unicode Support

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.