Update on conditions.

Richard U

Active Member
Joined
Feb 14, 2006
Messages
406
Office Version
  1. 365
  2. 2016
  3. 2010
  4. 2007
Platform
  1. Windows
I'm cleaning up a database that had inconsistent entries in a particular column.

I know I can run multiple updates like this

Code:
UPDATE temp SET [Shelf Name] = "SHELF 1"
Where [Shelf Name] = "SHELF1"

UPDATE temp SET [Shelf Name] = "SHELF 2"
Where [Shelf Name] = "SHELF2"

UPDATE temp SET [Shelf Name] = "SHELF 3"
Where [Shelf Name] = "SHELF3"

and so on.

Is there a way in access where I can do this in one query?

(sorry, very rusty in access)
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
I'm cleaning up a database that had inconsistent entries in a particular column.

I know I can run multiple updates like this

Code:
UPDATE temp SET [Shelf Name] = "SHELF 1"
Where [Shelf Name] = "SHELF1"

UPDATE temp SET [Shelf Name] = "SHELF 2"
Where [Shelf Name] = "SHELF2"

UPDATE temp SET [Shelf Name] = "SHELF 3"
Where [Shelf Name] = "SHELF3"

and so on.

Is there a way in access where I can do this in one query?

(sorry, very rusty in access)

Theres a pretty cool way of doing this with a combination of these two:

INSERT INTO
ON DUPLICATE KEY UPDATE

You should read up on that.

Note: this method is especially useful as you can use it to both update AND insert records.

An example on Stack Overflow http://stackoverflow.com/questions/...tiple-rows-with-different-values-in-one-query

<code style="margin: **** padding: **** border: **** font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;">INSERT INTO table_users (cod_user, date, user_rol, cod_office)
VALUES
('622057','12082014','student','123456'),
('2913659','12082014','assistant','123456'),
('6160230','12082014','admin','123456')
ON DUPLICATE KEY UPDATE
cod_user
=VALUES(cod_user), date=VALUES(date)</code>


Cheers,

Chris
 
Last edited:
Upvote 0
Try this:
Code:
UPDATE temp
SET [Shelf Name] = "SHELF " & Right([Shelf Name],1)
WHERE temp.[Shelf Name] In ("SHELF1","SHELF2","SHELF3");
 
Upvote 0

Forum statistics

Threads
1,221,805
Messages
6,162,074
Members
451,738
Latest member
gaseremad

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top