0

您好我的数据库中有两个表,一个包含“注册人姓名”字段和其他信息的注册人表和一个包含名为“Business_Identifier”的列的参考/查找表

想法是将“Registrant Name”字段中的数据与“Business_Identifier”列中包含的数据进行比较,以识别“Registrant Name”字段中包含的数据是企业还是个人的数据

一个例子是:

Registrant Table:
ID: 1234
Registrant NAme: ABC Ltd


Lookup Table:
ID:1,2,3                      
Business_Identifier: ltd,PLC,LLC

我希望创建一个存储过程,该过程将执行某种形式的模式匹配,获取查找表数据并查看其中是否出现在“注册人名称”字段中,从而将记录识别为企业。

我创建了一个在静态列表上执行模式匹配的脚本,请参见下面的示例,但我需要将静态列表转换为表格以便可以更新它

当前脚本:

With Test as (
SELECT *    
  FROM [Registrant_Table]
  where (patindex('%[0-9]%',UPPER([Registrant name])) > 0
     or patindex('%null%',UPPER([Registrant name])) > 0
     or patindex('%n/a%',UPPER([Registrant name])) > 0     
     or patindex('na',UPPER([Registrant name])) > 0
     or patindex('%LTD%',UPPER([Registrant name])) > 0
     or patindex('%None%',[Registrant name]) > 0
     or patindex('%unknown%',[Registrant name]) > 0
     or patindex('%Ltd%',[Registrant name]) > 0
     or patindex('%ltd%',[Registrant name]) > 0
     or patindex('%LLC%',[Registrant name]) > 0
     or patindex('%LLc%',[Registrant name]) > 0     
     or patindex('%LLP%',[Registrant name]) > 0
     or patindex('%LLp%',[Registrant name]) > 0       
     or patindex('%llp%',[Registrant name]) > 0
     or patindex('%Limited%',[Registrant name]) > 0          
     or patindex('%LIMITED%',[Registrant name]) > 0
     or patindex('%Limi%',[Registrant name]) > 0 
     or patindex('%Company%',[Registrant name]) > 0
     or patindex('%Tele%',[Registrant name]COLLATE Latin1_General_CS_AI) > 0  
     or patindex('%Trade%',[Registrant name]) > 0
     or patindex('%Host%',[Registrant name]) > 0
     or patindex('%Domain%',[Registrant name]) > 0
     )

select * 
Into [Registrant_Table_Business]
from Test

任何帮助将非常感激

谢谢

4

1 回答 1

0

upper如果查找表为和定义位列collation,您可以使用:

SELECT *    
  FROM [Registrant_Table] r
 CROSS JOIN [PatternLookup] l
 WHERE patindex('%' + l.Pattern + '%', 
        case when l.IsUpper = 1
             then case when l.IsLatin1_General_CS_AI = 1 
                  then upper (r.[Registrant name]) COLLATE Latin1_General_CS_AI
                  else upper (r.[Registrant name]) 
                  end
             else case when l.IsLatin1_General_CS_AI = 1 
                       then r.[Registrant name]  COLLATE Latin1_General_CS_AI
                       else r.[Registrant name]
                  end
        end) > 0

更新:为模式创建表:

create table PatternLookup
(
  PatternLookupID int identity primary key,
  Pattern nvarchar(100) not null,
  IsUpper bit default 0 not null,
  IsLatin1_General_CS_AI bit default 0 not null
)

并且很少插入:

   insert into PatternLookup (Pattern, isUpper, IsLatin1_General_CS_AI) values
          ('LTD', 1, 0),   -- This pattern asks for uppercased [Registrant name]
          ('Tele', 0, 1),  -- This one needs registrant in different collation
          ('Company', 0, 0)-- And this one is as-is
于 2012-07-20T10:16:26.620 回答