Click here to Skip to main content
16,018,802 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi..

How to update mutiple rows at a time. i have tried with the follwing update query.


SQL
UPDATE mytable
    SET fieldName= CASE other_field
        WHEN 1 THEN 'value'
        WHEN 2 THEN 'value'
        WHEN 3 THEN 'value'
        WHEN 4 THEN 'value'
    END
WHERE id IN (1,2,3, 4);


this query has worked for me but i have 65000 records, if i follow above query i have write 'when' statement for 65000 times. please send me the better solution for updating 65000 records at a time.


Thanks in Advance
Posted

1 solution

UPDATE tbl_name SET field_name = COALESCE((SELECT value FROM temp_tbl WHERE tbl_name.conditional_field = temp_tbl.condition_value), field_name),

field_name2 = COALESCE((SELECT value FROM temp_tbl2 WHERE tbl_name.conditional_field2 = temp_tbl2.condition_value), field_name2)

Try this i think it will help you
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900