Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to update a column in a table with unique values, but not all the rows, not incremented [duplicate]

Tags:

sql

Possible Duplicate:
Is it possible to perform multiple updates with a single UPDATE SQL statement?

I am updating a table with some new values for a particular column as below, so i am updating table Prepay, column PrepayTransactionDesc, on certain fows indicated by prepayId

update Prepay
set PrepayTransactionDesc = 'Funded Repeat Voucher 153429'
where prepayId = 58045

It works fine, but i want to do multiple updates. I have tried a few different ways but failed. the was i was trying to do it was using CASE when and then.

for instance, i have the following prepayid and prepaytransactiondesc fields

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

How would i do them in 1 go? It cant be that difficult but i seem to be missing something when i try to do the task.

like image 832
user1738096 Avatar asked Nov 23 '25 01:11

user1738096


1 Answers

You could try

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)
like image 164
Marc Avatar answered Nov 25 '25 18:11

Marc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!