Load result set to a table

Hello sql expert,

I have a query that output to a excel sheet daily and instead outputting to excel, I want to store those daily result set to a table without truncate the table. The purpose what I am trying to do is to keep those daily result set (historical)

Here is my simple sql query:

Select Column1, column2, datefield
From InventoryTbl
Where datefield = convert(date,getdate())

so, this query will run daily and I want to load the result set to this below table;
DailyTableLoad

the question, if I load today result set, can I keep today's result set for tomorrow load and so on?

Thanks all

insert into targettable ( Column1, column2, datefield)
Select Column1, column2, datefield
From InventoryTbl
Where datefield = convert(date,getdate())
1 Like

Thanks gbritton,

Will the next day result set overwrite the previous result set? or the result set will keep adding to the table?

It will keep adding to the table. If you want it to "overwrite", then truncate it first.

1 Like

No truncate, so this will be perfect to keep the historical data.

Thanks Tara.

It will keep adding

1 Like

Thank you gbritton

I tried to run my test query, it executed and I can see the result set in the DailyTableLoad table I created but the second time I re run the same query, I got this error:

There is already an object named 'DailyTableLoad' in the database.

Why are you trying to recreate the table?

1 Like

gbritton, I got it...I forgot to delete my create table. Thanks all for your help.