Home > SQL Server, T-SQL > Get the Unicode number for an Unicode character

Get the Unicode number for an Unicode character


UNICODE() function returns an integer value for a Unicode character. The function argument data type can be Nchar or Nvarchar. But, this function returns the Unicode value for the first character in the argument.

Versions

If you are using SQL Server version below 2012 then the output integer range is from 0 to 65535.

If you are using SQL Server 2012 the output integer value is between 0 to 1114111.

Example

set nocount on
declare @i as int

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

Thanks for reading.

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: