我有一个名为Services的表,它有两列ID和Price。这是我的代码(VB.NET):
com.CommandText = "UPDATE Services SET Price =
(CASE WHEN (ID = 'Bedsheet') THEN @Bedsheet WHEN (ID = 'Comforter')
THEN @Comforter WHEN (ID = 'PressOnly') THEN @PressOnly WHEN (ID = 'WDF')
THEN @WDF WHEN (ID = 'WDP') THEN @WDP END) WHERE ID IN
('Bedsheet','Comforter','PressOnly','WDF','WDP')"
它总是在查询表达式消息中说出语法错误(缺少运算符)。我需要在代码中纠正什么?
答案 0 :(得分:1)
从给予我帮助的人那里引用," CASE语法在SQL / Server中有效,但在ACE(Access本机SQL驱动程序)中不受支持。"我使用了Switch()函数来完成工作。这是我的新代码:
UPDATE Services SET Price = SWITCH(ID = 'Bedsheet', @Bedsheet, ID = 'Comforter', @Comforter, ID = 'PressOnly', @PressOnly, ID = 'WDF', @WDF, ID = 'WDP', @WDP)
WHERE ID IN('Bedsheet','Comforter','PressOnly','WDF','WDP')