开发者

a recursive string compare

开发者 https://www.devze.com 2022-12-14 07:49 出处:网络
Im not very strong on loops and recursive queries in T-SQL (might as well given that it\'s more of a set based language anyw开发者_如何学Pythonay) but I have still problem which I can\'t figure out wi

Im not very strong on loops and recursive queries in T-SQL (might as well given that it's more of a set based language anyw开发者_如何学Pythonay) but I have still problem which I can't figure out without the use of recursive query and a function?

I have 2 tables called Brands and Products.

CREATE TABLE Brands (RowID INT, BrandName VARCHAR(50))
CREATE TABLE Products (RowID Int, ProductName VARCHAR(50), BrandName VARCHAR(50))

So basically, I need to check each row in the Products table against the Brands table to see if the BrandName appears in the ProductName in the Products table. And if so, update the BrandName field in the products table.

Thanks.


As far as I can tell there's no need for recursion or loops to do this:

UPDATE Products
SET BrandName = 'updated value'
FROM Products AS p
    INNER JOIN Brands AS b
        ON p.ProductName LIKE '%' + b.BrandName + '%'
0

精彩评论

暂无评论...
验证码 换一张
取 消