可能的重复:
是否可以使用单个 UPDATE SQL 语句执行多个更新? https://stackoverflow.com/questions/412101/is-it-possible-to-perform-multiple-updates-with-a-single-update-sql-statement
我正在更新一个表,其中包含特定列的一些新值,如下所示,因此我正在更新表 Prepay、列 PrepayTransactionDesc、prepayId 指示的某些流
update Prepay
set PrepayTransactionDesc = 'Funded Repeat Voucher 153429'
where prepayId = 58045
它工作正常,但我想进行多次更新。
我尝试了几种不同的方法但都失败了。我当时正在尝试使用 CASE 来做到这一点。
例如,我有以下 prepayid 和 prepaytransactiondesc 字段
57770 Funded Repeat Voucher 153118
57771 Funded Repeat Voucher 153119
57772 Funded Repeat Voucher 153120
57773 Funded Repeat Voucher 153121
57774 Funded Repeat Voucher 153122
57775 Funded Repeat Voucher 153123
57776 Funded Repeat Voucher 153124
57894 Funded Repeat Voucher 153276
57895 Funded Repeat Voucher 153277
57896 Funded Repeat Voucher 153278
我该如何一次性完成它们?这不可能那么困难,但当我尝试完成这项任务时,我似乎错过了一些东西。
你可以尝试
UPDATE Prepay
SET PrepayTransactionDesc =
CASE
WHEN prepayID = 57770 THEN 'Funded Repeat Voucher 153118'
WHEN prepayID = 57771 THEN 'Funded Repeat Voucher 153119'
WHEN prepayID = nextID THEN 'Next Value'
END
WHERE prepayID in (1,2,4,57770... all your ids here)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)