July 19, 2022 at 6:33 pm
Should be a very basic query. Try
SELECT Object_Id, Schema_Name, Table_Name, SUM(Value1) AS Value1, MAX(Date1) AS Date1
FROM Table
GROUP BY Object_Id, Schema_Name, Table_Name
ORDER BY Object_Id, Schema_Name, Table_Name
July 20, 2022 at 9:24 pm
I would like to update Table2 with Table select statement results .But somehow it is not working.
update Tabl2 set Value1,Date1
SELECT Object_Id, Schema_Name, Table_Name, SUM(cast(Value1 as bigint)) AS Value1, MAX(Date1) AS Date1
FROM Table
GROUP BY Object_Id, Schema_Name, Table_Name
where Table.Object_id = Table2.object_id
July 21, 2022 at 1:51 am
Does this do what you need?
UPDATE a
SET a.Value1 = b.Value1,
a.Date1 = b.Date1
FROM Table2 AS a
JOIN (
SELECT Object_Id,
SUM(cast(Value1 as bigint)) AS Value1,
MAX(Date1) AS Date1
FROM Table1
GROUP BY Object_Id
) AS b ON a.Object_id = b.Object_id
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply