Reputation: 478
I've manipulated my data into the format I need it using a view, and now I have a simple insert query to write that data to a table:
insert into mytable
select * from myview
where
(myview.[date] > (select max([date]) from mytable))
and
(myview.[date] < getdate())
I'd like this to run automatically on a daily basis. I am a bit new to this, but my understanding is that I need to utilize a stored procedure. I am not sure how to execute this code in my stored procedure, though. When I create a new stored procedure, I'm given this template:
CREATE PROCEDURE [dbo].[Update]
@param1 int = 0,
@param2 int
AS
SELECT @param1, @param2
RETURN 0
Could someone help me understand how to bridge from query to stored procedure?
Upvotes: 1
Views: 867
Reputation: 69524
The procedure definition would be as simple as :
CREATE PROCEDURE dbo.Upload_data
AS
BEGIN
SET NOCOUNT ON;
insert into mytable
select * from myview
where
(myview.[date] > (select max([date]) from mytable))
and
(myview.[date] < getdate())
END
Once you have created the procedure , create a SQL Agent job which calls this procedure every day.
Upvotes: 2
Reputation: 2308
Run this and it will create a stored procedure in sql server called the_name_of_your_sproc.
CREATE PROCEDURE [dbo].[the_name_of_your_sproc]
AS
insert into mytable
select * from myview
where
(myview.[date] > (select max([date]) from mytable))
and
(myview.[date] < getdate())
Upvotes: 2