我正在标准化街道地址,我认为全文搜索,也许,可以解决我的问题。 我的问题是我有2毫秒的错误并且使用“LIKE”无法正常工作。 这就是我现在所拥有的:
UPDATE addresses
SET standarAddress = REPLACE (addresses.streetAddress, errors.streetAddress, corrects.streetAddress)
FROM corrects
INNER JOIN errors
ON corrects.id = errors.idCorrects
WHERE (addresses.streetAddress LIKE errors.streetAddress + ' ' + '[0-9]%')
但不是LIKE(最后一行)我想用这个:
WHERE CONTAINS(addresses.streetAddress, '@MyErrorVariable')
接下来是我的表格的一个真实例子:
--- addresses I want to standarize
CREATE TABLE addresses
(id INT PRIMARY KEY NOT NULL,
direccion VARCHAR(250))
GO
--- addresses with errors like Acrwod Driv instead of Acrewood Drive
INSERT INTO addresses VALUES (1,'Acrwod Driv 45249')
INSERT INTO addresses VALUES (2,'Advntur Lne 45242')
INSERT INTO addresses VALUES (3,'Aborcrek Lan 45242')
GO
--- corrects street addresses
CREATE TABLE corrects
(id INT PRIMARY KEY NOT NULL,
streetAddress VARCHAR(250) NULL)
GO
INSERT INTO corrects VALUES (1,'Acrewood Drive')
INSERT INTO corrects VALUES (2,'Adventure Lane')
INSERT INTO corrects VALUES (3,'Arborcreek Lane')
GO
--- errors form corrects street addresses
CREATE TABLE errors
(id INT PRIMARY KEY NOT NULL,
streetAddress VARCHAR(250) NULL,
idCorrects INT FOREIGN KEY REFERENCES corrects(id) NOT NULL)
GO
INSERT INTO errors VALUES (1,'Acrwod Driv',1)
INSERT INTO errors VALUES (2,'Advntur Lne',2)
INSERT INTO errors VALUES (3,'Aborcrek Lan',3)
我对constains的问题在于,在这个WHERE CONTAINS(addresses.streetAddress,'@ MyMyVisiable')中,我的@MyErrorVariable只接受像'Acrwod Driv'那样的值,我的所有错误都在错误表中。 请任何想法或帮助。 谢谢!
答案 0 :(得分:1)
全文不会有帮助,因为这是一个短语,创建全文索引需要一段时间?
如果你有一对一的关系正确错误
,为什么你有两个表?Fix
Wrong PK
Right
UPDATE addresses
SET standarAddress = REPLACE (addresses.streetAddress, Fix.Wrong, Fix.Right)
FROM addresses
INNER JOIN Fix
ON addresses.streetAddress LIKE Fix.Wrong + ' ' + '[0-9]%'
and standarAddress <> REPLACE (addresses.streetAddress, Fix.Wrong, Fix.Right)
你可能想要打破它,因为200万是一个大的交易日志
UPDATE addresses
SET standarAddress = REPLACE (addresses.streetAddress, Fix.Wrong, Fix.Right)
FROM addresses
INNER JOIN Fix
ON addresses.streetAddress LIKE Fix.Wrong + ' ' + '[0-9]%'
and standarAddress <> REPLACE (addresses.streetAddress, Fix.Wrong, Fix.Right)
and Substring(addresses.streetAddress, 0 , 1) = 'a'
and Substring(Fix.Wrong, 0 , 1) = 'a'
... b ... C 子串将使用索引