简体   繁体   English

如何使用MS SQL中的LIKE语句从表中选择包含大写字母的行仅包含西里尔字符的行

[英]How to select rows containing ONLY cyrillic characters in UPPERCASE from the table using LIKE statement in MS SQL

I want to select rows where column [Name] contains ONLY Cyrillic characters in UPPERCASE, and comma and hyphen from the table using LIKE : 我想选择其中列[Name]仅包含大写字母中的西里尔字符的行,以及使用LIKE从表中包含逗号和连字符的行:

SELECT  *
FROM    Clients
WHERE   NAME    LIKE '%[А-Я][,-]%' COLLATE Cyrillic_General_CS_AS

Or using explicit pattern: 或使用显式模式:

SELECT *
FROM Clients
WHERE NAME LIKE '%[АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ][,-]%' COLLATE Cyrillic_General_CS_AS

But these selects rows in which at least one character exists in pattern (but allows any other characters not exists in pattern). 但是这些选择了模式中至少存在一个字符的行(但允许模式中不存在任何其他字符)。

Maybe using ^ (NOT predicate) excluding any other characters like this: 也许使用^ (NOT谓词)排除任何其他字符,如下所示:

SELECT  *
FROM    Clients
WHERE   NAME    LIKE '%[^A-Z][./=+]%' COLLATE Cyrillic_General_CS_AS

But this requires enumeration a large number of unnecessary characters. 但这需要枚举大量不必要的字符。

How best to make a selection? 如何最好地做出选择?

Use a double negative. 使用双阴性。 Search for rows where the column doesn't contain at least one character not in the set you're interested in: 搜索列中不包含至少一个不在您感兴趣的集合中的字符的行:

SELECT *
FROM Clients
WHERE NAME NOT LIKE '%[^-АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ,]%' COLLATE Cyrillic_General_CS_AS

(I'm not quite sure what you were attempting to do by placing the hyphen and comma in a separate grouping, but I've moved them into the same group for now, since that seems to make some sense) (我不太确定你是通过将连字符和逗号放在一个单独的分组中来尝试做什么的,但我现在已将它们移到同一组中,因为这似乎有些意义)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM