Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

check current date

Posted on 2006-06-26
8
Medium Priority
?
367 Views
Last Modified: 2008-02-01
I only want to run some jobs on M - F, excluding the weekends.  i also need to exclude holidays.
i'm struggling right now to use my calendar table in the job scheduling, which simply is a calendar table, so to speak, indicative of whether the dates in the table are weekdays, weekends, holidays, etc.  Ultimately, I will use this, but right now I really need to modify the job scheduling post haste.  
So, in the interim, what's the right way to only invoke the proc if it's M, T, W, Th or F ?
i thought i could just preface it with an IF, making it execute conditionally, but, it's not working.  (syntax)
what's the right way to do this?

IF (SELECT datepart(dw, getdate()) BETWEEN 2 AND 6
do this.....
0
Comment
Question by:dbaSQL
[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
8 Comments
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 200 total points
ID: 16987263

DECLARE @dw INT
SET @dw = datepart(dw, getdate())  
IF (@dw >= 2 and @dw <= 6)
BEGIN
  -- do this
END
0
 
LVL 8

Assisted Solution

by:H
H earned 200 total points
ID: 16987276
I believe it would be much easier to schedule these procs in Sql server Agent's job scheduler then you can pick the specific dates?
0
 
LVL 70

Expert Comment

by:Scott Pletcher
ID: 16988010
SET DATEFIRST 7  --just to be sure
IF DATEPART(WEEKDAY, GETDATE()) BETWEEN 2 AND 6
BEGIN
    EXEC ...
    ...other command(s)...
END --IF
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 17

Author Comment

by:dbaSQL
ID: 16989163
well, in retrospect, you are right hollecar -- if, in fact, i only want to run M - F, sql server agent scheduling is quite fine, as it allows me to specifically schedule just that - M thru F and/or Saturday and Sunday.  angel and scott, both your suggestions do just that, too.  so, for the way I phrased myself, you've each answered my question, and I will split the points to each of you.  forgive me for having been a bit weird w/this question.

my problem remains, though, as I still cannot exclude holidays.  basically, i've got a whole bunch of agent jobs which i have to vpn in and disable intermittently on holidays and non-work days such that i'm not doing things like sending out blank reports of 'today's trades' for Christmas.  (you know what i mean)  

as i eluded above, I have a calendar table which has 2 years of dates -- attributes for each record are Year, MonthName, DayName, isHoliday, isWeekDay,  etc.  So all the info is there - i just need to someow utilize this with my job scheduling.  any insight or suggestions at all?  i thought possibly a udf that could be called within my procedures, but as of yet, i'm just not getting it together.  my table definition is below, would you guys have any direction/suggestions for me on this?

date - date in smalldatetime
Weekday  - bit  (is it a weekday?  )
Holiday   - bit  (is it a holiday? i.e., christmas, easter, etc., populated manually)
YR - Year
FY - fiscal year
Q - quarter
M - numerical representaiton of month
D - numerical representaiton of day
DW -numerical representaiton of week day
monthname - January, February, etc.
dayname - Monday, Tuesday, etc.
W - week number in the year that date falls in
HolidayDesc -- Christmas, Thanks Giving, etc.
0
 
LVL 70

Accepted Solution

by:
Scott Pletcher earned 200 total points
ID: 16992280
SET DATEFIRST 7  --just to be sure
IF DATEPART(WEEKDAY, GETDATE()) BETWEEN 2 AND 6
--add this code
AND NOT EXISTS (SELECT 1 FROM calendar WHERE date = CONVERT(CHAR(8), GETDATE(), 112) AND holiday = 1)
--end: add
BEGIN
    EXEC ...
    ...other command(s)...
END --IF
0
 
LVL 17

Author Comment

by:dbaSQL
ID: 16992400
oh, oh, very good, scott.  i could do this across the board, yes?  like i've got N number of different agent jobs which simply invoke procedures and do this and that.  couldn't i just preface the procedures w/this?
0
 
LVL 70

Expert Comment

by:Scott Pletcher
ID: 16992794
Yes, I would think so :-) .
0
 
LVL 17

Author Comment

by:dbaSQL
ID: 16992806
excellent, scott.  it works beautifully.  
i am splitting the points, as i said last night, and just forgot to do.
each of you, thanks very much.
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
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.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

704 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