SQLTeam.com | Weblogs | Forums

Load result set to a table


#1

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


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

#3

Thanks gbritton,

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


#4

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


#5

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

Thanks Tara.


#6

It will keep adding


#7

Thank you gbritton


#8

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.


#9

Why are you trying to recreate the table?


#10

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