How would I go about updating a table with statistics every 15minutes? I've got today a structured job that updates one other table with the same statistics but on a daily basis at 8:00 and 17:00. Though now I would like to use similar logic to update it every 15 minutes. My other job is using the SQL-server agent to exec the stored procedure twice everyday. Should I just use the same logic and change the update rate to every 15 minutes in the server agent?
So this is the code for the main insert stored procedure to check and insert data and it basically cehcks the activity between 17:00 and 8:00 also the amount of different parameters at 8:00.
If Convert(varchar(50),DATEPART(HH,getdate())) = '8'
begin
declare @datumstring as Varchar(30)
Declare @Datum As Datetime
set @Datum = Dateadd(dd,-1,GETDATE())
set @datumstring = convert(varchar, @Datum,102)
set @datumstring = @datumstring + ' 17:00'
set @Datum = CONVERT(datetime, @datumstring)
Then the insert mostly contains alot of subselects but it's not important here, although I'll post one of them so you can see how I use the date conditions.
(select COUNT(*) from table b
where b.ob = 4 and b.t = 7 and Time
between @Datum and GETDATE() and b.Name = LoginName)
Could I use the similar logic with time manipulation with variables or should I just make a similar insert into a table, then update that stored procedure every 15 minutes?
Cheers
Well as I understand you need something which will help you to execute some particular code block in every 15 minute.
So why not try WAITFOR keyword from sqlserver. Put you code in
WHILE (1 = 1)
BEGIN
WAITFOR DELAY '00:15'
-- CODE TO BE EXECUTE
END
Or can also use
WHILE (1 = 1)
BEGIN
WAITFOR TIME '00:15'
-- CODE TO BE EXECUTE
END
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With