我知道这很糟糕,我只是不知道如何重写它......任何帮助表示赞赏!
DECLARE @i INT,
@var VARCHAR(max)
SET @i = 0
WHILE 1 = 1
BEGIN
INSERT INTO mrs.dbo.nav_worldcheck_results
("counter",
"entity no",
"entity first name",
"entity last name",
"entity full name",
"worldcheck uid",
"worldcheck first name",
"worldcheck last name",
"worldcheck full name",
"percentage match")
SELECT TOP(1) [Counter] = @i,
EN.[entity no_],
EN.[name 2],
EN.[name],
EN.[name 2] + ' ' + EN.[name] AS EntityName,
SM.uid AS WorldCheckID,
SM.[first name],
SM.[last name],
SM.[first name] + ' ' + SM.[last name] AS WorldCheckName,
dbo.Fn_calculatejarowinkler(EN.[name 2] + ' ' + EN.[name],
SM.[first name] + ' ' + SM.[last name])
FROM [NAV_LIVE].dbo.[entitytable$entity] AS EN
CROSS JOIN [NAV_LIVE].dbo.[worldcheck master] AS SM
WHERE ( EN.inactive = 0 )
AND dbo.Fn_calculatejarowinkler(EN.[name 2] + ' ' + EN.[name],
SM.[first name] + ' ' + SM.[last name]) >= .75
AND NOT EXISTS(SELECT *
FROM mrs.dbo.nav_worldcheck_results AS WCR
WHERE EN.[entity no_] = WCR.[entity no]
AND WCR.[worldcheck uid] = SM.uid)
SET @i = @i + 1
END
我想避免 where 语句中重复的函数调用,我尝试将所有变量分配为变量然后进行处理,但我陷入了你不能将集合与数据检索混合在一起的陷阱,而且我可怜的小大脑处于星期五模式!:o/