Home > SQL Server, T-SQL > Get Unicode character using NCHAR() function

Get Unicode character using NCHAR() function


NCHAR() function returns Unicode character for a given integer value. This character is as defined by Unicode standards. You can read more about Unicode standard here.

Collation play a vital role in retrieving the correct Unicode character. If the collation setting does not contain the supplementary character (SC) then we can use this range of integer from 0 through 65535. If it contains SC then we can use the range of integer from 0 through 1114111.

If the argument value is not given as given in the above specified range then the output will be NULL.

Experiment

set nocount on
declare @i as int

set @i = 0
while  @i <= 65535
begin
print ‘Unicode character for  ‘+ cast(@i as varchar(5)) + ‘  is ‘ + nchar(@i)
set @i = @i + 1
end

This T-SQL statement prints Unicode character from 0 to 65535.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: