希望你能帮助我理解我的想法:
我有table
包含数据并创建了一些查询(大约10-15)来更新fruitclass
字段:
UPDATE [tblFruit] SET fruitclass = "Apple"
WHERE Fruit_Name Like "*apple*";
'this is a separate query
UPDATE [tblFruit] SET fruitclass = "Orange"
WHERE Fruit_Name Like "*orange*";
依此类推......
那么现在,想问一下是否可以将这些多个查询合并为一个?或者我会坚持单独的查询?谢谢!
答案 0 :(得分:0)
考虑使用IIF()
条件逻辑表达式:
UPDATE [tblFruit] SET fruitclass = IIF(Fruit_Name Like '*apple*', 'Apple', NULL),
fruitclass = IIF(Fruit_Name Like '*orange*', 'Orange', NULL),
-- ...add comma-separated expressions
;
或嵌套IIF()
,但可能会弄乱10-15个表达式:
UPDATE [tblFruit] SET fruitclass = IIF(Fruit_Name Like '*apple*', 'Apple',
IIF(Fruit_Name Like '*orange*', 'Orange', NULL))
;