Sunday, February 17, 2013

SQL SERVER UNICODE STRING FUNCTION

SQL SERVER UNICODE STRING FUNCTION

UNICODE String function returns UNICODE value of first character in the STRING.

select nchar(UNICODE(N'हिन्दी'))
O/P:ह

select UNICODE(N'हिन्दी'))

O/P:  2361

Ex: Get each Unicode Characters of nvarchar String  हिन्दी

declare @position int, @txt nvarchar(max);
set @position=1;
set @txt = N'हिन्दी';

while @position <= len(@txt)
begin

declare @t int;
select @t=unicode(substring(@txt,@position,1))
print '&#'+ CONVERT(nvarchar(5),@t)+';'
set @position = @position+1
end

O/P:

&#2361;
&#2367;
&#2344;
&#2381;
&#2342;
&#2368;
 
Note:Copy this unicode characters and put in HTML Page user can get  word Hindi in Hind Lanugage .i.e
हिन्दी


Ex:Get Unicode characters of German String  

"Die komplette Familie ist auf dem Cover der britischen Zeitschrift "Hello!"

declare @position int, @txt nvarchar(max);
set @position=1;
set @txt = N'Die komplette Familie ist auf dem Cover der britischen Zeitschrift "Hello!';

while @position <= Datalength(@txt)
begin

declare @t int;
select @t=unicode(substring(@txt,@position,1))
print '&#'+ CONVERT(nvarchar(5),@t)+';'
set @position = @position+1
end

&#68;
&#105;
&#101;
&#32;
&#107;
&#111;
&#109;
&#112;
&#108;
&#101;
&#116;
&#116;
&#101;
&#32;
&#70;
&#97;
&#109;
&#105;
&#108;
&#105;
&#101;
&#32;
&#105;
&#115;
&#116;
&#32;
&#97;
&#117;
&#102;
&#32;
&#100;
&#101;
&#109;
&#32;
&#67;
&#111;
&#118;
&#101;
&#114;
&#32;
&#100;
&#101;
&#114;
&#32;
&#98;
&#114;
&#105;
&#116;
&#105;
&#115;
&#99;
&#104;
&#101;
&#110;
&#32;
&#90;
&#101;
&#105;
&#116;
&#115;
&#99;
&#104;
&#114;
&#105;
&#102;
&#116;
&#32;
&#34;
&#72;
&#101;
&#108;
&#108;
&#111;
&#33;


Note:Copy this unicode characters and put in HTML Page user can get  word 
"
D i e k o m p l e t t e F a m i l i e i s t a u f d e m C o v e r d e r b r i t i s c h e n Z e i t s c h r i f t " H e l l o !"
 
Tags: SQL SERVER UNICODE STRING FUNCTION,SQL SERVER NCHAR STRING FUNCTION,How to get all unicodes and characters from a String,get all unicodes and unicode characters from a String.

No comments:

Post a Comment