如何查找 SQL 服务器中的记录是否包含罗马数字?

how to find if a record has roman numerals in SQL Server?

我想检测来自 table(SQL 服务器)的记录是否有罗马数字。

Table有数据如下:

    Column A | Column B
-----------------------------
1            | AMC I XYZAQS
2            | ABC IV 2 XYZQWS
3            | ANR XVI ANCVP
4            | SWD POL 2#

因此,结果将是前 3 条记录

这个呢?

DECLARE @dummy TABLE(A INT,B VARCHAR(100));
INSERT INTO @dummy VALUES
 (1,'AMC I XYZAQS')
,(2,'ABC IV 2 XYZQWS')
,(3,'ANR XVI ANCVP')
,(4,'SWD POL 2#');

WITH Casted AS
(
    SELECT A
          ,B
          ,CAST('<x>' + REPLACE((SELECT B AS [*] FOR XML PATH('')),' ','</x><x>') + '</x>' AS XML) InParts
    FROM @dummy
)
,Splitted AS
(
    SELECT A
          ,B
          ,x.value('.','nvarchar(max)') AS part 
    FROM Casted
    OUTER APPLY InParts.nodes('x') AS Parts(x)
)
SELECT * FROM Splitted
WHERE UPPER(part) NOT LIKE '%[0-9ABEFGHJKNOPQRSTUWYZ]%' 

结果

A   B               part
1   AMC I XYZAQS    I
2   ABC IV 2 XYZQWS IV
3   ANR XVI ANCVP   XVI

这不会检查任何罗马数字规则。它只检查是否存在特殊字符