Hi @kkran
If I understand correctly, you want the query to be able to clear data from earlier in the same day and insert the latest data every time you run it.
You can add a delete statement before inserting data to clear data from earlier in the same day.
Just like this:
Declare @Snapshot DATETIME = GETDATE()
SELECT column1, column2, column3, column4, column5, column6
,SnapShotDatetime
FROM [USDW].[dbo].[Table1]
delete from [USDW].[dbo].[Table1]
where convert(char(10),SnapShotDatetime,111) = convert(char(10),@Snapshot,111);
INSERT INTO [USDW].[dbo].[Table1] (column1, column2, column3, column4, column5, column6
,SnapShotDatetime)
Select column1, column2, column3, column4, column5, column6,@Snapshot
from OPENQUERY ( Linkedserver, 'Select * from LinkedTable')
Best regards,
Percy Tang
If the answer is the right solution, please click "Accept Answer". If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.