Solved

Stored Procedure to run every day at midnight

Posted on 2007-12-06
15
1,145 Views
Last Modified: 2008-02-01
Hi guys
I sort of  know how to write a stored procedure but IS there any way to get it to run every day at midnight  on a shared platform where I not setup a scheduled task to actually run the SP?

What I want to do is delete all records from Classifieds where DateExpired > Date + 30.

Is it better to run this on the default.asp page someway and execute the SP before I select the latest records?

I am running on sql2005
0
Comment
Question by:clearchannel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 2
  • +1
15 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20418662
do you have access to the sql agant scheduling?
0
 
LVL 10

Expert Comment

by:answer_me
ID: 20418686
1. You can scehdule a sql job.
2. whenever you are accessing from asp page you need to ensure that job has run successfully otherwise call the stored procedure directly before proceeding.
0
 

Author Comment

by:clearchannel
ID: 20418760
I don't have access to the Agent only the following options under SQL2005.

Database
  <my db name>
Security
  logins
  server roles
  credentials
Server Objects
  backup devices
  Linked Servers
  Triggers

Replication

Management
   Activity Monitor
   Database Mail
   DTC

0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 25

Expert Comment

by:imitchie
ID: 20418771
Use task scheduler to add a job for SQLCMD. Check SQLCMD /? from the command line

SQLCMD <server> <login> <db> <sqlcommand>
0
 

Author Comment

by:clearchannel
ID: 20418830
I do not have access to this sort of functionality.
If you read my message I am on shared SQL environment with a hosting company!
0
 
LVL 25

Expert Comment

by:imitchie
ID: 20418855
Default.asp is your best bet then - but if users can bookmark other pages, then make it a global include page.
Make it perform a
delete .. classified .. where date..
on every single page that must not see old classifieds.
0
 

Author Comment

by:clearchannel
ID: 20418955
Yeah but thats going to be processor intensive when I have over 1000 users acessing the site on a daily basis. I would rather run something once every night somehow.

is there no other way to do what I want?
0
 
LVL 25

Accepted Solution

by:
imitchie earned 250 total points
ID: 20418983
Okay, you have access to your system via HTTP right???
How about a scheduled task on your machine, can you handle that?
Just find a simple vbscript that will connect and ask for a .asp page. You can do the delete there....
0
 

Author Comment

by:clearchannel
ID: 20419008
Again, that relies on my pc being on the intenrnet at the time or even being powered up!

0
 
LVL 25

Expert Comment

by:imitchie
ID: 20419034
I don't know about ASP, but PHP code allows access to filesystems, so you can keep track using a status file. PHP doesn't mind checking many files for each page production, so I assume the same thing would work if ASP can manipulate files.

It's not really that intensive to fire a query on a properly indexed table. A page may run anywhere from 1-20 queries and still produce pages quite quickly.
0
 

Author Comment

by:clearchannel
ID: 20419045
I think I am going to execute a scheduled asp page to run.

BUT what is wrong with my code below?

SELECT * FROM dbo.Classifieds
WHERE (DateCreated+ TimePeriod + 30) >= Date()
0
 
LVL 25

Expert Comment

by:imitchie
ID: 20419051
SELECT * FROM dbo.Classifieds
WHERE (DateCreated+ TimePeriod + 30) >= GetDate()

assuming timeperiod is datetime
0
 
LVL 25

Expert Comment

by:imitchie
ID: 20419055
Probably use functions:

SELECT * FROM dbo.Classifieds
WHERE DateAdd(d, 30, DateCreated+ TimePeriod) >= GetDate()
0
 

Author Comment

by:clearchannel
ID: 20419135
I have chaged the above to

"SELECT * FROM dbo.Classifieds WHERE DateAdd(d, 7, DateCreated+TimePeriod) < GetDate()"

Can someone please clarify that that call should select all records where the createdDate+timeperiod+7 < todays date
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20419418
you might be interested by the following:
http://technet.microsoft.com/en-us/library/ms187331.aspx

the WAITFOR would allow you to run at a given time...
now, you could "loop" to make it "scheduled" every week, or just run a script on your machine to connect once per day to run that...
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question