sql - Perform multiple updates in a single query in an access database table -
in access 2016 database, have table tblcustomerinfo field customer_code. there old customer_code values need updated newer values (for example, rows customer_code = 103 should updated customer_code = 122).
i can achieve going 1 customer_code @ time using queries like:
update tblcustomerinfo set customer_code = 122 customer_code = 103; update tblcustomerinfo set customer_code = 433 customer_code = 106; ... however, avoid having run separate query each customer_code. there way update codes, each different new value, in single query?
create table eg customercodes 2 fields oldcode , newcode, , add in values. run update query this:
update customercodes inner join tblcustomerinfo on customercodes.oldcode = tblcustomerinfo.customer_code set customers.customer_code = [customercodes].[newcode]; alternative
if there aren't many change can use switch statement this:
update tblcustomerinfo set customer_code = switch(customer_code=103,126, customer_code = 106,130, customer_code = 107,133); there is, in experience, limit on number of pairs can have in switch statement, although have never bothered find out limit - doesn't seem documented.
Comments
Post a Comment