我在SQL Server中编写了一个SQL查询,我需要用一个字符串值替换多个字符串值。例如在SQL查询中替换多个字符串
Product Quantity
------- --------
Apple 2
Orange 3
Banana 1
Vegetable 7
Dairy 6
将成为
Product Quantity
------- --------
Fruit 2
Fruit 3
Fruit 1
Vegetable 7
Dairy 6
我知道如何做到这一点的唯一方法是使用嵌套替换SELECT子句。
SELECT
REPLACE('Banana', REPLACE('Orange', REPLACE('Banana', Product, 'Fruit'),
'Fruit'), 'Fruit') AS Product
FROM
Table
有没有更简单的方法?
编辑:产品类别中可能有其他值。参见上面的编辑示例。
这是有帮助的。谢谢。 – 2009-02-02 18:10:30