我正在尝试从excel表单元格中获取数据并使用此查询更新mysql表
sqlstr = "UPDATE " & table4 & " SET price = CASE WHEN key_id = '" & Cells(i, 1) & "' " & " THEN " & Cells(i, 8) & " " & " WHEN key_id = '" & Cells(i, 2) & "' " & " THEN " & Cells(i, 9) & " " & " ELSE: price "
它给了我一个错误:
在':price'
附近使用的语法
好吧,如果我在最后删除单词价格,它会给我一个错误:
在"附近使用的语法
我想我错过了一些引用的地方。我该如何解决这个问题?
答案 0 :(得分:1)
错误1 :
" ELSE: price
应为" ELSE " & price
错误2 :
END
子句
CASE
sqlstr = "UPDATE " & table4 & " SET price = CASE WHEN key_id = '" & Cells(i, 1) & "' THEN " & Cells(i, 8) & " WHEN key_id = '" & Cells(i, 2) & "' THEN " & Cells(i, 9) & " ELSE " & price & " END"