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.
Author |
Topic |
divan
Posting Yak Master
153 Posts |
Posted - 2012-10-30 : 14:42:17
|
How do I write a script that will not run a job on a weekend that is Saturday and Sunday. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-10-30 : 15:08:19
|
add a condition likeWHERE DATEDIFF(dd,0,GETDATE())%7 < 5------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
divan
Posting Yak Master
153 Posts |
Posted - 2012-10-31 : 08:09:09
|
Good Morning Visakh16.. Can you please tell me what %7 in the condition mean .... Thanks |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-10-31 : 09:00:56
|
% is the modulo operator - it returns there remainder if left operand is divided by the right. E.g. 12%7 = 5The logic of what Visakh was doing is as follows:Datediff function counts the number of days from the the second operand (0, which is Jan 1, 1900 - which was a Monday) to the current date.So:if today is also a Monday, the difference between 1/1/1900 and today will be an exact multiple of 7, so the remainder will be zero.if today is a Tuesday,the difference will be a multiple of 7 plus 1, so the remainder will be 1and so on...if today is a Saturday,the difference will be a multiple of 7 plus 5, so the remainder will be 5if today is a Sunday,the difference will be a multiple of 7 plus 6, so the remainder will be 6So, if the remainder is less than 5, it is Monday-Friday, i.e., weekday. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
divan
Posting Yak Master
153 Posts |
Posted - 2012-10-31 : 11:30:43
|
Thank you for the explanation this makes a lot of sense and I am learning so much for you guys.. I wish there was a way for me to reciprocate the help... |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-10-31 : 11:59:52
|
you will be able to soon..------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|
|
|