You can do it this way:

UPDATE table_users
    SET cod_user = (case when user_role = 'student' then '622057'
                         when user_role = 'assistant' then '2913659'
                         when user_role = 'admin' then '6160230'
                    end),
        date = '12082014'
    WHERE user_role in ('student', 'assistant', 'admin') AND
          cod_office = '17389551';

I don't understand your date format. Dates should be stored in the database using native date and time types.

Answer from Gordon Linoff on Stack Overflow
🌐
Medium
medium.com › geekculture › update-multiple-rows-in-sql-with-different-values-at-once-7d2eddb0b85f
Update multiple rows in SQL with different values at once | by Tadej Golobic | Geek Culture | Medium
June 12, 2021 - Well, first, I started googling a little bit and i found this SQL solution: UPDATE users SET firstName = (case when id = 1 then 'encryptedFirstName1' when id = 2 then 'encryptedFirstName2' when id = 3 then 'encryptedFirstName3' end) WHERE id in (1, 2, 3); Looks nice doesn’t it? But one senior developer at my first job, always asked me, can we do it differently?
Discussions

mysql - Updating multiple rows with different values in one query - Database Administrators Stack Exchange
I am trying to understand how to UPDATE multiple rows with different values and I just don't get it. The solution is everywhere but to me it looks difficult to understand. For instance, two update... More on dba.stackexchange.com
🌐 dba.stackexchange.com
June 28, 2014
Multiple rows updation in sql server
Hi experts , Below is the database which i have created in sql server . I have a datagridview in a form where a user in , column0 writes the productnames and in column2 writes the consumed quantity . The problem is that i dont know how to update… More on learn.microsoft.com
🌐 learn.microsoft.com
2
0
October 14, 2023
Update multiple rows with different values in SQL - Stack Overflow
I have a table like this: SKU Size A 10 B 10 C 10 D 10 E 10 F 10 G 10 I want to change it to: ... More on stackoverflow.com
🌐 stackoverflow.com
Updating multiple rows with different values – SQLServerCentral Forums
Unfortunately many employees have ... with SQL statements. I have already developed the Query to pull all the necessary information should someone accidently make a mistake (EX: writing an UPDATE statement without specifying a WHERE clause --which has happened many times before), but now I am trying to write a script that will use the information I pulled from above and RE-INSERT the old value back into the appropriate table. The problem is that I am going to need to update multiple rows with DIFFERENT ... More on sqlservercentral.com
🌐 sqlservercentral.com
September 22, 2007
🌐
Edureka Community
edureka.co › home › community › categories › web development › php › mysql - update multiple rows with different...
MySQL - UPDATE multiple rows with different values in one query | Edureka Community
June 1, 2020 - Hello, I wanted to know how to UPDATE multiple rows with different values and I just don't get it ... in the WHERE and in the IF condition.Any ideas?
🌐
Baeldung
baeldung.com › home › sql queries › update multiple rows with different values with single query
Update Multiple Rows With Different Values With Single Query Baeldung on SQL
June 20, 2025 - To do this, we can use a SQL CASE statement to allow us to provide multiple values for a range of conditions, all within a single query: UPDATE users SET user_type = (CASE WHEN age >= 18 THEN 'ADULT' WHEN age < 18 THEN 'JUNIOR' END);
🌐
Quora
quora.com › How-do-you-update-multiple-values-in-SQL
How to update multiple values in SQL - Quora
Use a WHERE clause that targets multiple rows. Example: UPDATE orders SET status = 'cancelled' WHERE order_date < '2024-01-01' AND status = 'pending'; 3) Update many rows with different values (row-specific)
Find elsewhere
🌐
TablePlus
tableplus.com › blog › 2018 › 11 › how-to-update-multiple-rows-at-once-in-mysql.html
How to update multiple rows at once in MySQL? | TablePlus
November 12, 2018 - INSERT INTO students (id, score1, score2) VALUES (1, 5, 8), (2, 10, 8), (3, 8, 3), (4, 10, 7) ON DUPLICATE KEY UPDATE score1 = VALUES(score1), score2 = VALUES(score2); Need a good GUI Tool for MySQL? TablePlus is a modern, native tool with an elegant UI that allows you to simultaneously manage ...
🌐
DEV Community
dev.to › chidioguejiofor › scenario-1-making-updates-to-multiple-fields-56hl
Scenario 1: When You Need to Update Multiple Rows with Different Values – The Smart Way! - DEV Community
September 30, 2024 - In this article, we’ll explore how to efficiently update multiple rows with different values in a single query to minimize database overhead and improve performance.
🌐
Quora
quora.com › How-do-I-update-multiple-rows-of-a-single-column-in-SQL
How to update multiple rows of a single column in SQL - Quora
Answer: Actually that’s real easy. The problem is trying NOT to update the rows you don’t want updated. Let’s assume that you have a column where a few, many or all of the values have a NULL value, but, for whatever reason they should have a value like true or false.
🌐
GeeksforGeeks
geeksforgeeks.org › sql › how-to-update-multiple-records-using-one-query-in-sql-server
How to Update Multiple Records Using One Query in SQL Server? - GeeksforGeeks
In this case, we can use the CASE ... syntax: UPDATE table_name SET column_value = CASE column_name WHEN 'column_name1' THEN column_value1 WHEN 'column_name2' THEN column_value2 ELSE column_value END WHERE column_name IN('column_name1', 'column_name2');...
Published   July 23, 2025
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 1391320 › multiple-rows-updation-in-sql-server
Multiple rows updation in sql server - Microsoft Q&A
October 14, 2023 - The SubmitButton_Click function saves the changed rows. ... It looks like you can pass the DataTable as a parameter and update it in bulk.
🌐
DataCamp
datacamp.com › tutorial › update-multiple-columns-sql
How to Update Multiple Columns in SQL | DataCamp
November 8, 2024 - My writing bridges technical depth ... and accuracy. Yes, you can update multiple rows with different values by using conditions in the WHERE clause or applying logic within the CASE statement....
🌐
W3Schools
w3schools.com › sql › sql_update.asp
SQL UPDATE Statement
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition; Note: Be careful when updating records in a table! Notice the WHERE clause in the UPDATE statement. The WHERE clause specifies which record(s) that should be updated.
🌐
SQLServerCentral
sqlservercentral.com › forums › topic › updating-multiple-rows-with-different-values
Updating multiple rows with different values – SQLServerCentral Forums
September 22, 2007 - Unfortunately many employees have ... with SQL statements. I have already developed the Query to pull all the necessary information should someone accidently make a mistake (EX: writing an UPDATE statement without specifying a WHERE clause --which has happened many times before), but now I am trying to write a script that will use the information I pulled from above and RE-INSERT the old value back into the appropriate table. The problem is that I am going to need to update multiple rows with DIFFERENT ...
🌐
SitePoint
sitepoint.com › databases
Multiple UPDATE, same column, different values, different WHERE conditions - Databases - SitePoint Forums | Web Development & Design Community
August 9, 2008 - I’ve found plenty of info around about updating multiple rows with the same value using “WHERE columname IN”, and I’ve got that down. But, I’m needing to UPDATE a column in multiple rows with a different value for each WHERE condition. My updates are being done as individual queries like this: UPDATE tablename SET widget='zamu-xxx' WHERE widget='zamu'; UPDATE tablename SET widget='flabu-yyy' WHERE widget='flabu'; Is there any way to do something like this in a single query?
Top answer
1 of 2
8

Couldn't find a SQL Server 2008 fiddle engine so I had to opt for a SQL Server 2014 ... so not sure if the following will work in SQL Server 2008, but fwiw ...

Setup some sample data:

create table Table1(id int, Date datetime null);
create table Table2(id int, Date datetime);

insert Table1 values (1,null)
insert Table1 values (1,null)
insert Table1 values (2,null)
insert Table1 values (2,null)
insert Table1 values (2,null);

insert Table2 values (1,'2013-01-29 08:50:00.000')
insert Table2 values (1,'2013-01-29 15:28:00.000')
insert Table2 values (2,'2013-01-31 11:56:00.000')
insert Table2 values (2,'2013-03-11 16:08:00.000')
insert Table2 values (2,'2013-01-31 14:04:00.000');

Keeping in mind that we haven't been provided (yet) with any means to determine which rows to match between Table1 and Table2 for a given id value, I'll just let row_number() generate a 'matching' rowid.

And then we'll make use of SQL Server's ability to update Table1 via a derived table definition:

update T1 
set    T1.Date=T2.Date

from   (select row_number() over(partition by id order by Date) as rowid,
               id,
               Date
        from   Table1 
        where  Date is NULL) T1

join   (select row_number() over(partition by id order by Date) as rowid,
               id,
               Date
        from   Table2) T2

on      T1.id    = T2.id
and     T1.rowid = T2.rowid;

And the results:

select * from Table1;

id  Date
--- --------------------
1   2013-01-29T08:50:00Z
1   2013-01-29T15:28:00Z
2   2013-01-31T11:56:00Z
2   2013-01-31T14:04:00Z
2   2013-03-11T16:08:00Z

And here's a SQL Fiddle for the above.

2 of 2
3

You stated that the order of the matching matters but it seems like you don't have anything to ORDER BY in table 1 to create a guaranteed order to match the other table and there is no way in SQL Server to order the rows after insertion date, because information about that is not stored. With this in mind it’s not possible to do a matching with the result you want. There is a solution to update the rows with an arbitrary match within each id. If that would be good enough.

UPDATE t 
SET    t.[date] = tt.[date] 
FROM   (SELECT *, 
               Row_number() 
                 OVER ( 
                   partition BY id 
                   ORDER BY [date]) AS rno 
        FROM   Table1) AS t 
       INNER JOIN (SELECT *, 
                          Row_number() 
                            OVER ( 
                              partition BY id 
                              ORDER BY [date]) AS rno 
                   FROM   Table2) AS tt 
               ON t.id = tt.id 
                  AND t.rno = tt.rno 

This solution will match all rows individually but can't guarantee the order.

DB Fiddle

🌐
DEV Community
dev.to › azophy › how-to-update-multiple-rows-based-on-list-of-key-val-pairs-in-mysql-mariadb-postgresql-4lpp
How to update multiple rows based on list of key-val pairs (in MySQL, MariaDB, & PostgreSQL) - DEV Community
September 29, 2023 - So I'll just write my findings here. as this version doesn't support VALUES clause yet, our only choice is to use the ugly CASE-WHEN syntax: UPDATE table_name SET changed_col = CASE comparison_col WHEN 'key1' THEN 'value1' WHEN 'key2' THEN 'value2' ...
🌐
DbSchema
dbschema.com › blog › tutorials › sql update statement – syntax, examples, and best practices | dbschema
SQL UPDATE Statement – Syntax, Examples, and Best Practices | DbSchema
August 23, 2025 - Let's say we want to update the Name of Alice to 'Alicia' and her Age to 24. The query would be: UPDATE Students SET Name = 'Alicia', Age = 24 WHERE StudentID = 2; ... In this case, both the Name and Age of the record with StudentID 2 were updated.