sql - UPDATE a field in one table with the SUM of another -


i'm trying set value of field in table sum of set of fields in table by:

update table1  set fieldtoupdate =  (     select sum(fieldtosum) table2 )  thirdfield = 'a' 

but i'm not having luck. i've seen lot of examples use joins, 2 tables aren't related in way.

thanks

while subquery should work, break this:

declare @s int;  select @s = sum(fieldtosum) dbo.table2;  update dbo.table1 set fieldtoupdate = @s fieldtoupdate = 'a'; 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -