I have two tables called daily and master. Daily table is truncated every day but Master table holds the data and is never truncated. Every day I run a SQL script to merge the Daily table data with Master table as below inside a stored procedure:
UPDATE master
SET offset = COALESCE(offset + 1, 0);
MERGE INTO master m
USING daily d
ON (m.id = d.id)
WHEN MATCHED THEN
UPDATE SET offset = 0
WHEN NOT MATCHED THEN
INSERT (id, col1, col2, col3, offset)
VALUES (d.id, d.col1, d.col2, d.col3, NULL);
This works fine but in the WHEN NOT MATCHED clause, I need to Insert only a maximum of 100 records from Daily to Master. No there is no sorting criteria for the data to be inserted. How can I achieve this ?