我已经尝试通过删除SQL Server中描述字段中的部分文本来更新此脚本:
UPDATE products
SET description = LEFT(description, CHARINDEX('<b>Please select xxxx</b>', description) - 1)
WHERE productid = 'abc'
它工作正常,但我无法动态更新所有产品。
答案 0 :(得分:2)
UPDATE products
SET description = Replace(description, '<b>Please select xxxx</b>', '')
WHERE description LIKE '%<b>Please select xxxx</b>%';
答案 1 :(得分: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, '');
---只有当你确定没有太多产品时:)