Try this:

 Update MasterTbl Set
    TotalX = Sum(D.X),    
    TotalY = Sum(D.Y),    
    TotalZ = Sum(D.Z)
 From MasterTbl M Join DetailTbl D
    On D.MasterID = M.MasterID
 

Depending on which database you are using, if that doesn't work, then try this (this is non-standard SQL but legal in SQL Server):

 Update M Set
    TotalX = Sum(D.X),    
    TotalY = Sum(D.Y),    
    TotalZ = Sum(D.Z)
 From MasterTbl M Join DetailTbl D
     On D.MasterID = M.MasterID

As mentioned in comments, if your database software does not allow the use of From clauses in Updates, then you must use the subquery approach mentioned in several other answers

Answer from Charles Bretana on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ sql โ€บ sql_update.asp
SQL UPDATE Statement
Below is a selection from the Customers ... = 1, with a new contact person AND a new city. UPDATE Customers SET ContactName = 'Alfred Schmidt', City= 'Frankfurt' WHERE CustomerID = 1;...
๐ŸŒ
Quora
quora.com โ€บ How-do-you-update-multiple-values-in-SQL
How to update multiple values in SQL - Quora
If you mean โ€œHow does one update multiple column values within a row or rows in a table with a single statement?โ€ then witness: UPDATE mytab SET col1=val1, col2=(col2*1.5), col3=(col4 / 3) WHERE keycol IN (1223, 34234, 5332 ); Some RDBMSโ€™s ...
๐ŸŒ
Beansoftware
beansoftware.com โ€บ T-SQL-FAQ โ€บ set-multiple-variables-select.aspx
How To Set Multiple Variables By Using SELECT In Stored Proc
Using the same logic, if we want to set value of two, three or more variables, we could try something like: ... DECLARE @CurrentCategory INT DECLARE @DatePublished DATETIME DECLARE @Visits INT SET @CurrentCategory = (SELECT CategoryID FROM Articles WHERE ID = @ID) SET @DatePublished = (SELECT ...
๐ŸŒ
Microsoft
social.msdn.microsoft.com โ€บ Forums โ€บ sqlserver โ€บ en-US โ€บ 7061308c-a5aa-4a02-aced-539d9b9a0d29 โ€บ how-to-query-multiple-values-in-a-single-set-statement
How to query multiple values in a single SET statement? | Microsoft Learn
November 30, 2021 - Think about how this would work. The destination is a single column; a column by definition is a scalar value. A list physically will not fit. However, if you had an ANSI/ISO Standard SQL you can assign rows like this SET a,b,c,.. = (1,2,3, ..);
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ sql โ€บ how-to-update-multiple-columns-in-single-update-statement-in-sql
How to Update Multiple Columns in Single Update Statement in SQL? - GeeksforGeeks
We will set the CITY value to 'Unknown' for these records. This approach efficiently updates multiple records in a single query. ... n this update, the CITY column has been set to 'Unknown' for all individuals with an AGE less than 30. As shown, the update was applied only to the matching rows based on the condition in the WHERE clause. The SQL GROUP BY clause is used to arrange similar data into groups.
Published ย  July 23, 2025
Find elsewhere
๐ŸŒ
MSSQLTips
mssqltips.com โ€บ home โ€บ when to use set vs select for assigning sql server variables
When to use SET vs SELECT for assigning SQL Server Variables
November 25, 2009 - Whenever you are assigning a query returned value to a variable, SET will accept and assign a scalar (single) value from a query. While SELECT could accept multiple returned values. But after accepting multiple values through a SELECT command you have no way to track which value is present in the variable.
๐ŸŒ
Spiceworks
community.spiceworks.com โ€บ programming & development โ€บ databases & queries
Setting multiple values to a variable - Databases & Queries - Spiceworks Community
August 1, 2014 - Hey Spiceheads - Is it possible to use an IN operator or select statement when setting a variable? I need to add multiple IDโ€™s on line 5 where I am setting the @PT variable. IF OBJECT_ID('tempdb..#tmp') IS NOT NULL DROP TABLE #tmp Declare @PT int set @PT=401 --Need to add multiple ID's here Declare @DN int set @DN=2121 Select distinct p.perf_no INTO #tmp From T_PERF AS p join TX_PERF_PMAP pp on p.perf_no=pp.perf_no WHERE p.prod_season_no = 8079 and pp.price_type=@PT DECLARE @X int Se...
๐ŸŒ
Sqlfreelancer
sqlfreelancer.com โ€บ blog โ€บ passing-multiple-values-into-a-variable
Passing Multiple Values into a Variable | SQL Freelancer Blog
May 14, 2015 - So unless I have 1,2 in the same ID column, it will show 0 results. One way to get around this is to use a UDF, user defined function. In this function, weโ€™re going to convert the comma separated values (1,2) into a table, then query from that.
๐ŸŒ
ProjectPro
projectpro.io โ€บ recipes โ€บ enter-single-and-multiple-values-table-sql
SQL Values - How to Enter Single and Multiple Values in a Table in SQL? -
January 11, 2024 - SET column1 = value1, column2 = value2, ... ... This updates the salary for employees with the last name 'Doe' to 55000. This recipe has covered the basics of entering single and multiple values into a table in SQL.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ update multiple columns in sql
Update Multiple Columns in SQL - Scaler Topics
May 4, 2023 - In the above example, we have updated the roll_no, name, address, and age of the last row. The SQL GROUP BY clause is used with the SELECT statement to arrange identical data into groups. ... The GROUP BY clause is used in the SELECT statement after the WHERE command and before the ORDER BY command. To learn more about using GROUP BY with multiple columns, click here. We can update the columns of a table using the UPDATE statement. The SET command is used inside the UPDATE statement to specify the columns to update.
Top answer
1 of 2
2

As mentioned in the comment, it completely depends on what you plan to do with the parameter as to the best method to accomplish this (and perhaps to add even how you get the selected values to be stored). If you can elaborate on those 2 things, we can probably give you better suggestions.

One thing you can easily use to store multiple values without having to get into parsing those values back out is to use table variables:

DECLARE @Params TABLE (A NVARCHAR(MAX))
INSERT @Params VALUES
    ('ABC'), ('DEF'), ('GHI'), ('JKL')
SELECT * FROM @Params

If you must iterate over the list, you can modify this to add an identity to simplify the logic.

DECLARE @Params TABLE (A NVARCHAR(MAX), Id INT NOT NULL IDENTITY(1,1))

Now you can iterate with logic like this:

DECLARE @i INT = 0
WHILE EXISTS (SELECT * FROM @Params P WHERE Id >= @i) BEGIN
    SELECT * FROM @Params P WHERE Id = @i
    SET @i = @i + 1
END

Or for scenarios where you only wish to process each unique value once, you can just use a DELETE (no need for additional identity attribute):

DECLARE @A NVARCHAR(MAX)
WHILE EXISTS (SELECT * FROM @Params P) BEGIN
    SET @A = (SELECT TOP 1 A FROM FROM @Params P)
    -- Perform any work
    DELETE @Params WHERE A = @A 
END
2 of 2
0

I don't know if this is going to help but... there is a type called cursor, it's like a vector or an array. It's used like this:

CURSOR name IS SELECT something
FROM some_table;

That way you can store a lot of information in a cursor called "name". To iterate through its values, you can use a loop like this:

OPEN name;

LOOP

    FETCH name INTO x;
    EXIT WHEN name%NOTFOUND;

    dbms_output.put_line(x);

END LOOP;

CLOSE name;

This way you print all values stored. Hope that helped!

๐ŸŒ
DotFactory
dofactory.com โ€บ sql โ€บ update
SQL UPDATE
They can be separated with a semicolon (;) and submitted as a group (called a batch). Alternatively, use an UPDATE with a WHERE clause. Here is the syntax. UPDATE table-name SET column1 = value1, ... WHERE condition ยท An example condition would be: WHERE Id IN (53,24,95,106).
๐ŸŒ
SQL Shack
sqlshack.com โ€บ what-to-choose-when-assigning-values-to-sql-server-variables-set-vs-select-t-sql-statements
This article explores the SQL variables using SET and Select SQL Statements.
December 5, 2019 - Again, if we try to assign values from database table to multiple variables, it requires us SET statements equal to the number of variables. In our example, we need two SET statements to assign values from the SetVsSelectDemo table to the @EmpName and @EmpGrade variables as shown in the script below: On the other hand, only one SELECT statement can be used to assign values from the SetVsSelectDemo table to the @EmpName and @EmpGrade SQL variables, using simpler query as shown clearly below:
๐ŸŒ
StudySmarter
studysmarter.co.uk โ€บ sql set
SQL SET: Definition, Example & Syntax | StudySmarter
August 8, 2023 - The following SQL command demonstrates this: UPDATE EmployeesSET JobTitle = 'Senior Developer', Salary = 85000WHERE EmployeeID = 10;This command updates both the JobTitle and Salary of the employee whose EmployeeID is 10, clearly showing the utility of the SET keyword in modifying multiple ...