0

我已尝试通过删除 SQL Server 中描述字段中的部分文本来更新此脚本:

UPDATE products
SET description = LEFT(description, CHARINDEX('<b>Please select xxxx</b>', description) - 1)
WHERE productid = 'abc'

它工作正常,但我无法将它动态更新到所有产品。

4

2 回答 2

2
UPDATE products
SET    description = Replace(description, '<b>Please select xxxx</b>', '')
WHERE  description LIKE '%<b>Please select xxxx</b>%';
于 2013-07-30T08:49:52.960 回答
0

可能使用 case-when 条件:

UPDATE  products
SET     Description = REPLACE(Description,
                       CASE WHEN ProductId = 1 THEN 'Your pattern for product 1'
                            WHEN ProductId = 2 THEN 'Your Pattern for Product 2'
                            -- WHEN ProductId = 3 THEN ...
                            ELSE '' -- Default empty
                       END, '');

--- 仅当您确定没有太多产品时 :)

于 2013-07-30T09:04:37.347 回答