I have two tables: 'SingleTable' and 'SummaryTable' Then there is a function which summarizes some entries from SingleTable and writes it to SummaryTable.
Everytime a SummaryTable entry is inserted, there is also Summary Key as an attribute (not a pk, not unique). Now i want to write the created summary key in each SingleTable entry which was summarized.
Creating the SummaryTable entries (e.g.):
INSERT INTO SummaryTable
(some column names)
SELECT DISTINCT
(some column names)
FROM SingleTable
WHERE
(some criteria)
I wrote something like this to get the latest created summary key:
UPDATE SingleTable
SET summarykey =
(SELECT summarykey
FROM SummaryTable
WHERE id = @@IDENTITY
)
WHERE
(some criteria)
But as far as i unterstand i would have to run it everytime an summary was created and not after the INSERT INTO statement has finished.
Any idea how to do this?