Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Stored Procedure to find data and insert

Author  Topic 

KingCarlos
Yak Posting Veteran

74 Posts

Posted - 2012-01-18 : 20:03:54
Hi there

I have the following SQL Query that I wish to run as a SP can anyone point me in the correct direction

insert into Warranties (cid, contid, dwdate, serialno)
SELECT cid, contid, dwdate, serialno FROM items WHERE DWARRANTY >= dateadd(day, datediff(day, 0, getdate()), 1)
and DWdate < dateadd(day, datediff(day, 0, getdate()), 7)

thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-01-18 : 20:43:51
create proc SomeProcName
as
your query goes here

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

KingCarlos
Yak Posting Veteran

74 Posts

Posted - 2012-01-18 : 21:00:32
Thanks - If I am running SQL Express is there any way to have this stored procedure to run every day?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-01-18 : 21:13:08
Yes. You can schedule it to run via Windows Task Scheduler. You would setup a job in there that calls sqlcmd.exe to execute your script or command. There are other ways to do it in Express, but I personally think Task Scheduler is simplest.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2012-01-19 : 04:22:17
I don't use SQL Express, but I thought there was an add-on available similar to SQL Agent in the main SQL product?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-01-19 : 12:23:19
quote:
Originally posted by Kristen

I don't use SQL Express, but I thought there was an add-on available similar to SQL Agent in the main SQL product?



There are products out there that you can buy to get a SQL Agent, but I don't see the point of them. You can also use a fancy way like this: http://www.sqlteam.com/article/scheduling-jobs-in-sql-server-express

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2012-01-19 : 13:43:45
Sorry Tara, I should have Googled before posting. No such MS SQL Agent for Express, plenty of wannabe solutions ... but Windows Task Scheduled and SQLCMD or somesuch is the best alternative, albeit a bit "pants" compared to SQL Agent.
Go to Top of Page
   

- Advertisement -