1

Much like this question in MySQL, I am trying to retain special characters such emojis into an nvarchar type column. However, any emojis are converted to "??". I have tried to reproduce the question's solution including changing column type and collation in SQL Server but haven't succeeded.

What I am attempting to do:

INSERT INTO TableName 
(Id, Title, Description) 
VALUES
(1, 'This is my title 😀','Here is a description with a 📻 radio');

Where Title and Description columns are nvarchar(255).

The resulting insert looks like:

| Id | Title               | Description                           |
|----|---------------------|---------------------------------------|
| 1  | This is my title ?? | Here is a description with a ?? radio |

Using this to create the table

CREATE TABLE TableName(
  Id INT PRIMARY KEY,
  Title NVARCHAR(255),
  Description NVARCHAR(255)
);

The database's collation is SQL_Latin1_General_CP1_CI_AS

4
  • While asking a question, you need to provide a minimal reproducible example: (1) DDL and sample data population, i.e. CREATE table(s) plus INSERT T-SQL statements. (2) What you need to do, i.e. logic and your code attempt implementation of it in T-SQL. (3) Desired output, based on the sample data in the #1 above. (4) Your SQL Server version (SELECT @@version;). Commented Nov 22, 2022 at 15:03
  • 1
    Use a N'Unicode literal'. Commented Nov 22, 2022 at 15:14
  • 1
    Try: INSERT INTO TableName (Id, Title, Description) VALUES (1, N'This is my title 😀', N'Here is a description with a 📻 radio'); Commented Nov 22, 2022 at 15:15
  • Thanks! That was surprisingly easy Commented Nov 22, 2022 at 15:18

1 Answer 1

3
    INSERT INTO TableName(Title,Description) 
    VALUES (N'👍 🖒 🖓 🖕 🗑 🛦 ⁉ 😎 😔 😇 😥 😴 😭',
            N'👍 🖒 🖓 🖕 🗑 🛦 ⁉ 😎 😔 😇 😥 😴 😭');

Use the prefix string literal with " N' <"my strange text"> ' "

Try this "select" statement as well:

    SELECT N'👍 🖒 🖓 🖕 🗑 🛦 ⁉ 😎 😔 😇 😥 😴 😭'
Sign up to request clarification or add additional context in comments.

1 Comment

This looks like you've copied some of this from this answer, as the emoticons are identical.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.