tsql - SQL function from Latin to Cyrillic -


i looking ms sql function make translit latin cyrillic. have completed solution? (for example, 'spasibo' -> 'спасибо')

create function dbo.tocyrillic (     @str nvarchar(max) ) returns nvarchar(max) begin     -- declare return variable here     declare @inputlength int     declare @i int     declare @latinsymbol nvarchar(2)     declare @cyrillicsymbol nvarchar(2)     declare @outputvalue nvarchar(max)      set @outputvalue=n''     set @inputlength=len(@str)     set @i=1      declare @transtable table (uppercyr nvarchar(2) collate cyrillic_general_ci_as,                                  lowercyr nvarchar(2) collate cyrillic_general_ci_as,                                  lowerlat nvarchar(2), cid int primary key identity(1,1))      insert @transtable values (n'А', n'а', n'a')     insert @transtable values (n'Б', n'б', n'b')     insert @transtable values (n'В', n'в', n'v')     insert @transtable values (n'Г', n'г', n'g')     insert @transtable values (n'Д', n'д', n'd')     insert @transtable values (n'Ђ', n'ђ', n'đ')     insert @transtable values (n'Е', n'е', n'e')     insert @transtable values (n'Ж', n'ж', n'ž')     insert @transtable values (n'З', n'з', n'z')     insert @transtable values (n'И', n'и', n'i')     insert @transtable values (n'Ј', n'ј', n'j')     insert @transtable values (n'К', n'к', n'k')     insert @transtable values (n'Л', n'л', n'l')     insert @transtable values (n'Љ', n'љ', n'lj')     insert @transtable values (n'М', n'м', n'm')     insert @transtable values (n'Н', n'н', n'n')     insert @transtable values (n'Њ', n'њ', n'nj')     insert @transtable values (n'О', n'о', n'o')     insert @transtable values (n'П', n'п', n'p')     insert @transtable values (n'Р', n'р', n'r')     insert @transtable values (n'С', n'с', n's')     insert @transtable values (n'Т', n'т', n't')     insert @transtable values (n'Ћ', n'ћ', n'ć')     insert @transtable values (n'У', n'у', n'u')     insert @transtable values (n'Ф', n'ф', n'f')     insert @transtable values (n'Х', n'х', n'h')     insert @transtable values (n'Ц', n'ц', n'c')     insert @transtable values (n'Ч', n'ч', n'č')     insert @transtable values (n'Џ', n'џ', n'dž')     insert @transtable values (n'Ш', n'ш', n'š')       while (@i<=@inputlength)     begin         set @latinsymbol=substring(@str,@i,1)         set @cyrillicsymbol=@latinsymbol    -- if not found below, use char (e.g. numbers etc)          if ((@latinsymbol collate croatian_cs_as)=upper(@latinsymbol))         begin             select top 1 @cyrillicsymbol=uppercyr @transtable lowerlat=lower(@latinsymbol) order cid         end         else         begin             select top 1 @cyrillicsymbol=lowercyr @transtable lowerlat=lower(@latinsymbol) order cid         end         set @i=@i+1         set @outputvalue=@outputvalue+@cyrillicsymbol     end      return @outputvalue  end 

Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -