How to find Cyrillic font (russian characters)?

Idea is to find all values that contains Cyrillic font (russian characters).

Something like:

SELECT CASE 
         WHEN Name LIKE /* Cyrillic font / russian characters */ THEN '1' 
         ELSE Name 
       END AS Filter

I can't find any info about It, so I can't provide what I've tried.

For example:

  Name
Александр -- This is Cyrillic (have russian characters, should return 1)
John      -- This should be returned as normal Name

Have you any ideas?

Upvotes: 1

Views: 5874

Answers (2)

Vuhasty
Vuhasty

Reputation: 36

Had same task to resolve.

next code works for me

declare 
  @codeEN nvarchar(50) = N'EN',
  @codeUA nvarchar(50) = N'УА'

select 
  IIF(@codeEN = CAST(@codeEN as varchar(50)), 1, 0) EN_IsLatin,
  IIF(@codeUA = CAST(@codeUA as varchar(50)), 1, 0) UA_IsLatin

Result:

EN_IsLatin  UA_IsLatin
----------- -----------
1           0

Upvotes: 0

Bernd Linde
Bernd Linde

Reputation: 2152

As per comment:

This Q&A gives a good way of doing this in SQL-Server (Can't mark as duplicate, since it is a different kind of question):

Solution:

select *,                               --  ▼ space added here
       case when TheName like '%[^-A-Za-z0-9 /.+$]%'
         then '1'
         else TheName
      end as 'Filter'
  from CyrillicTest

You can either adjust the RegEx string to match all the Cyrillic characters or adjust it to cater for hyphenated ASCII names (and all other weird things parents put into their kids names). I am not sure about the speed of this against a big table, so please test it.

Testbed:

create table CyrillicTest
     ( TheID   int identity(1,1) not null,
       TheName nvarchar(50)      not null )

insert CyrillicTest
     ( TheName )
values
     ( 'AName' ),
     ( 'Александр' ),
     ( 'CName' )

Output:

TheID       TheName       Filter
----------- ------------- -------------
1           AName         AName
2           Александр     1
3           Thirdname     Thirdname

Upvotes: 3

Related Questions