我有一个表变量,其中包含要从查询结果中替换的单词列表。
我想600
在表变量中搜索这些词中的任何一个。我只是为了这个例子做了3。然后,如果找到的话,我想替换它。我得到了结果,但每个字都重复。我有一个 UDF,它采用公司名称中的每个单词并查看它是否匹配。
declare @findreservedwords table
(findWord varchar(50) primary key)
INSERT INTO @findreservedwords
VALUES
('Inc','LLC','Corp.')
--actually I have over 500 records in the @findreservedwords table variable. Just 3 for this example
select distinct p.product_id,replace(c.Company_Name,f.findword,'') as NewCompanyName,f.findWord,sep.col
FROM PRODUCT p
INNER JOIN COMPANY c on p.Manufacturer_ID = c.company_id
CROSS APPLY dbo.SeparateValues(c.company_name, ' ') sep
LEFT OUTER JOIN @findreservedwords f on f.findWord = sep.col
WHERE p.product_id = 100
这回归...
Product_ID NewCompanyName FindWord Col
100 null null Sony
100 Sony Inc LLC LLC
100 Sony LLC Inc Inc
我想让它只返回一个结果,并且“LLC”和“Inc”都将被删除,因为这些词在保留词表变量中。所以字符串“Sony LLC Inc”
将会...
Product_ID NewCompanyName
100 Sony