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
 how do i execute sql at midnight? PST

Author  Topic 

kingpoop
Starting Member

6 Posts

Posted - 2010-11-08 : 00:08:39
Hello:

I am trying to run some code within an IF statement and I only want to execute the code block at midnight

what am i doing wrong?

IF GETDATE() BETWEEN '23:59' AND '00:30'
BEGIN
...
END

Thanks for your help.

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-11-08 : 01:05:38
what version of SQL server you are using ?
Go to Top of Page

kingpoop
Starting Member

6 Posts

Posted - 2010-11-08 : 01:06:47
SQL Server 2008
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-11-08 : 02:49:06
Why don't you schdule a job to run at midnight.
You don't have to worry about checking the time and calling the code based on time format.

Go to Top of Page

kingpoop
Starting Member

6 Posts

Posted - 2010-11-08 : 02:51:28
this sproc is called by a single job and the job calls several sprocs. this particular sproc can only run at midnight.

i cannot use another job for this task.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-11-08 : 02:57:32
You have opened three threads for the same problem.
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=152661
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=152660
Please don't do that because it is difficult for us to help in this case.

And please correct your CAPS LOCK because writing in UpperCase is like shouting us!


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-11-08 : 03:03:25
Something to start with:


Getdate between
dateadd(mi,-1,dateadd(d,1,dateadd(d,datediff(d,0,getdate()),0)))
Between
dateadd(mi,30,dateadd(d,1,dateadd(d,datediff(d,0,getdate()),0)))
Go to Top of Page

TimSman
Posting Yak Master

127 Posts

Posted - 2010-11-08 : 12:40:03
why is this sproc called by another one if it should only run once a day?
Go to Top of Page

kingpoop
Starting Member

6 Posts

Posted - 2010-11-09 : 13:02:49
quote:
Originally posted by TimSman

why is this sproc called by another one if it should only run once a day?



It's not called by another sproc. There is a job that calls six sprocs and this one is the 6th and final sproc. When this sproc is called i need to check if the time is midnight...if yes, then perform some tasks.
Go to Top of Page
   

- Advertisement -