SQL Server provides the NCHAR function to return a unicode character from the number code. In this article, we will learn how to use NCHAR in SQL Server.
The basic syntax of a NCHAR is as follows:
SELECT NCHAR(num_code);
For this, we will be using docker. This is recommended for more than just using SQL Server. To find how to install docker go here: https://docs.docker.com/engine/install/
Now create a file called docker-compose.yml
and add the following.
version: "3.9"
services:
db:
image: "mcr.microsoft.com/mssql/server"
ports:
- 1433:1433
environment:
SA_PASSWORD: "Your_password123"
ACCEPT_EULA: "Y"
Open a terminal and go to the folder the file is located. Then run the following.
docker-compose up
If you are looking for another good reference, you can check here: https://docs.docker.com/samples/aspnet-mssql-compose/.
A good list of unicode numbers is on the Wikipedia page here: https://en.wikipedia.org/wiki/List_of_Unicode_characters.
To use the function, let's try to get the character for number code 474.
select nchar(474) as unicode;
unicode |
---|
ǚ |
Scroll down the list on Wikipedia, and we can try the character for code 934.
select nchar(934) as unicode;
unicode |
---|
Φ |