How to run a SQL Server Agent job step on certain days/frequency

I've a SQL Server Agent job. One of the requirement is that a particular step should only run on certain frequency i.e. Certain Date and time. Any suggestions how can that be done?
GBM

yes
1. Make first step as a Transact SQL step. Keep command as below
IF DAY(GETDATE()) = <Your date value>
AND DATEPART(hh,GETDATE()) = <your time hour)
AND DATEPART(minute,GETDATE()) = <your time minute)
SELECT 1
ELSE
RAISERROR 'Job cant be run at this time'
Then for job step properties set the following properties in advanced tab
This would make sure it will quit the job without executing other core steps untill it reaches the required day and time
You can add more conditions in IF based on requirement like if you want time to be on certain second or month to be particular value etc
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

Similar Messages

  • SQL Server Agent Job steps

    I've searched and can't find the answer to this, would like to post it in the appropriate forum. (Using SQL Server 2008R2) I'm having trouble with a long string of email addresses in one of my SQL Server Agent Jobs. I'd like to edit it for readability but
    can't find a way to do it. Currently smashing all the addresses together works,  The job executes and returns the correct data and sends the desired emails, but if I try a continuation character it sends emails to the first person on the list, then no
    others.
    It works fine when all the email addresses have to be in one long string with no spaces. (Example below) Hard to read/edit.
    ,@recipients ='[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected]'

    Prashanth, This runs every two hours five days a week for the last two years. The only problem I have with it is that the line of email addresses is difficult to read and edit when employees leave and are replaced. 
    Thanks for looking at this for me - We like it because it's easy for smart phone users to read when they're out and about. EDITED TO ADD: Although this interface wraps the address line, in Microsoft's SQ: Server Agent, the line just stretches off to the
    right apparently infinitely.  DietSquirt
    --Query for updates to QC db mail
    --Delivers results in body of email
    SET NOCOUNT ON;
    use QC 
    Declare @bodytext nvarchar(150)
    exec msdb.dbo.sp_send_dbmail
    @profile_name = 'Send Mail'
    ,@recipients ='[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected];[email protected]'
    ,@reply_to = [email protected]'
    ,@subject = 'Updates to QC - ALL LOCATIONS'
    ,@execute_query_database = QC
    ,@attach_query_result_as_file  = 0
    ,@query_result_header= 0
    , @query_result_no_padding = 1
    ,@query_result_width = 6500
    ,@query_result_separator = '    '
    ,@query =
    SET NOCOUNT ON
    declare @startdate datetime
    ,@enddate datetime
    ,@Location nvarchar(20)
    set @startdate = DATEADD (hour , -12 , GETDATE() )
    set @enddate = GETDATE()
    select
     '' Updates to QC''
    select
    [The main query goes here]

  • SQL Server Agent Job Step: Can I run in single step?

    Hi:
    I have a SSIS package that I am running from a SQL Agent job. I have to run a msdb Stored procedure first and then run the package. So I have created 2 steps. step-1, type =Tra-SQL where I am running my Stored Procedure. And then step-2, type= Integration
    Services which is running the package. I am attaching a config file here too. Is there a simple way to do these 2 steps in just 1 single step without too much complexities. 
    In the step-1 , SQl command=EXEC MySQlProcedure
    In the step-2 , by default the commandline=/SQL "MyPackage" /SERVER MySqlSer /CONFIGFILE "MyDataConfig.dtsConfig" /CHECKPOINTING OFF /REPORTING E
    Thanks.

    The stored procedure actually gives permission to any user who wants to run the job. I found only I (the creater) and DBA can run the job but other users could not. So I asked the DBA to set it up and he then created this SP. Is there any other way where
    I can give access to every user or only DBA can do it?

  • Running an SQL Server Agent Job to execute a package but the job FAILS on Connections

    I have created a package which basically imports data from one database to another, The database where it collects the data from the job is failing on connecting reporting the following message:
    Source: ****** Connection manager "Source - *****"     Description: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80040E4D.  An OLE DB record is available.  Source: "Microsoft
    OLE DB Provider for SQL Server"  Hresult: 0x80040E4D  Description: "Login failed for user '*ConnectionONE*'.".  End Error  Error: 2015-02-18 11:36:04.94     Code: 0xC020801C    
    Source: Data Flow Task Get Revenue Data [1]     Description: SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER.  The AcquireConnection method call to the connection manager "Source - *****" failed with error
    code 0xC0202009.
    The package runs fine if executed within the package but fails from the SQL Agent Job.
    NB * is to hide confidential data. *ConnectionONE* is the database which the package is attempting to get data from.
    Completely puzzled on what to do as i have tried reading other forumns but they dont seem to be helping.
    Any Help would be great thankyou!

    That is because package is set to "EncryptSensitiveWithUserKey". Please change that to "EncryptSensitiveWithPassword" and the provide password to protect sensitive data.
    More information
    here.
    Regards,
    Vishal Patel
    Blog: http://vspatel.co.uk
    Site: http://lehrity.com

  • SSIS running through SQL Server agent Job Fails --SQL Server 2012

    Hi All,
    I am getting the below error.
    Executed as user: sak\thiru. ...ion 11.0.2100.60 for 64-bit  Copyright (C) Microsoft Corporation. All rights reserved.    Started:  3:31:17 PM  Error: 2014-03-07 15:32:22.46     Code: 0xC0202009     Source: CommonDataSource
    Connection manager "TESTDB"     Description: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80004005.  An OLE DB record is available.  Source: "Microsoft SQL Server Native Client 11.0"
     Hresult: 0x80004005  Description: "Login timeout expired".  An OLE DB record is available.  Source: "Microsoft SQL Server Native Client 11.0"  Hresult: 0x80004005  Description: "A network-related or instance-specific
    error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.".
     An OLE DB record is available.  Source: "Microsoft SQL Server Native Client 11.0"  Hresult: 0x80004005  Description: "Named Pipes Provider: Could not open a connection to SQL Server [53]. ".  End Error  Error:
    2014-03-07 15:32:43.58  
     The package execution fa...  The step failed.
    I checked namedpipes, ports,services, SqlBrowser all are running fine.
    share your views.
    Thanks
    Thiru
    Thiru

    Hi Thiru,
    The error messages are rather general and the issue may occur due to various causes. You can check the “Connect Time” setting of the Connection Manager "TESTDB", and increase its timeout value.
    If the issue persists, maybe it occurs because the Windows Firewall or certain anti-virus software blocks the RPC dynamic range of TCP Ports between SQL Server and Domain Controllers. In this case, temporarily disable third party anti-virus software, or
    configure RPC dynamic port allocation to work with firewalls referring to the following KB article
    http://support.microsoft.com/kb/154596.
    In addition, the issue may be related to the SQL Server that the OLE DB Source adapter connects to. You can check the SQL Server log to see if any error occurs at that time.
    Hope this helps.
    Regards,
    Mike Yin
    TechNet Community Support

  • SSIS Package Fails when Scheduled as a SQL Server Agent Job

    I have an SSIS package that runs without any problems when executed through BIDS.
    However, when I schedule the SSIS as an Agent job, it fails completely or part way through. When it partially runs, the part that it is failing on is a Script Task that moves the source data file to an archive folder (on the same server).
    I have tried using my domain account as the owner of the job, then the job fails straight off and I get an error:
    Unable to determine if the owner (Domain\MyID) of job JobName has server access (reason: Could not obtain information about Windows NT group/user 'Domain\MyID'
    If I change the owner to the 'sa' account , then the job partially runs, but then fails because 'sa' is a SQL account and does not have access to the filesystem.
    I have managed to get it to work by using the SQL2008_Local account and granting modify permissions to the affected folders.
    My question is - what is the advised way of doing this?
    Thanks
    Gary

    Hi Garyv.King,
    When you see a SSIS package fails running in a SQL Agent job, you need to first consider the following conditions:
    1. The user account that is used to run the package under SQL Server Agent differs from the original package author.
    2. The user account does not have the required permissions to make connections or to access resources outside the SSIS package.
    For more detailed information about the issue, please following this KB article:
    An SSIS package does not run when you call the SSIS package from a SQL Server Agent job step
    http://support.microsoft.com/kb/918760 
    You can check SQL Server Agent’s activity logs, Windows Event logs and SSIS logs to get more clues. Also the tool Process Monitor is helpful to track the cause of registry or file access related issues.
    The following 4 issues are common encountered in the SSIS forum.
    1. The package's Protection Level is set to EncryptSensitiveWithUserKey but your SQL Server Agent service account is different from the SSIS package creator.
    2. Data source connection issue.
    3. File or registry access permission issue.
    4. No 64-bit driver issue.
    For more information about it, please see:
    How do I troubleshoot SSIS packages failed execution in a SQL Agent job:
    http://social.technet.microsoft.com/Forums/en-US/sqlintegrationservices/thread/e13c137c-1535-4475-8c2f-c7e6e7d125fc 
    Thanks,
    Eileen

  • SQL Server Agent Job Scheduler- Set time less than 10 seconds

    Hi,
    Could any one please let me know how to change the SQL server agent Job scheduler time to less than 10 secs?
    I wan to schedule a SSIS package run for every 5 secs.
    Thanks..

    Be careful, it is a bad idea to blindly just issue a new package run without knowing whether the previous package ended.
    It may lead to locking/dead-locking.
    Now re the Agent: the seconds are not exposed at all, why you say 10?
    But, there is a way, not through the UI, explained there:http://stackoverflow.com/questions/5569415/is-there-a-way-to-set-a-sql-server-job-scheduled-to-run-every-30-seconds + http://www.sqlservercentral.com/articles/Administration/sqlserverjobscheduling/2288/
    PS you can have it every sec
    Arthur My Blog

  • SQL Server Agent Job

    I want to learn how to create a SQL Server Agent Job. After I googled it, I see that it can be found under Databases under Object Explorer, But I don't see that option. Can someone tell me where is it or how can i create one? I also need to
    understand the steps to create one. (I just have basic knowledge of SQL Server of using small queries like Update, Delete, Select statements, etc). A plain english explanation would be very helpful.

    BOL: "Create a Job
    This topic describes how to create a SQL Server Agent job in SQL Server 2014 by using SQL Server Management Studio, Transact-SQL, or SQL Server Management Objects (SMO)."
    https://msdn.microsoft.com/en-us/library/ms190268.aspx
    See SSMS image for new job:
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Database Design
    New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014

  • SQL Server Agent Job And Database Mail - Error formatting query, probably invalid paramters

    We have a stored procedure that we are trying to call with a SQL Server Agent Job. The stored procedure calls Database Mail. This is SQL 2008. The execute task is simply:
    USE [Production]
    GO
    EXEC [dbo].[JOB_EMAIL_SCHEDULED_REPORTS]
    GO
    When the job runs, it is erroring out immediately, with the error:
    Execute as user: NT AUTHORITY\NETWORK SERVICE. Error formatting query, probably invalid paramters [SQLSTATE 42000] (Error 22050). The step failed.
    When we go into SQL Server Manager and just execute the SQL query, it works though. Something within the SQL Server Agent job,  and Database Mail is causing problems. Any ideas? Thanks.

    Justin,
    If you use SSMS then the procedure is executed under a different user when compared to running using a SQL Server Agent Job.
    Isolate the problem by running a SQL Server agent job that sends a mail. Also check if the NT Authority\Network Service account is
    in good standing. Look at the below thread with a similar problem that had an expired account.
    http://social.msdn.microsoft.com/Forums/en/sqltools/thread/bac7ecee-a156-4313-b532-ba15813a0700
    http://SankarReddy.com/

  • What SQL Server Agent jobs are currently running and for how long

    Is there a way to tell what SQL Server Agent jobs are currently running and for how long?  View history isn't working in my case because it's only showing completed jobs.  John Schroeder

     You can use the "Job Activity Monitor" for doing this.  Do the following steps. It will open up the Job Activity Monitor.
    1.    In Object Explorer, connect to an instance of the SQL Server Database Engine, and then expand that instance.
    2.    Expand SQL Server Agent.
    3.    Right-click Job Activity Monitor and click View Job Activity.
    4.    In the Job Activity Monitor, you can view details about each job that is defined for this server.
    In Job Activity Monitor page, we have column called Status. It will indicate whether job is executing or idle. Last Run column will give you the last invocation time of this job.
    Use the following link for further reference.
    http://msdn.microsoft.com/en-us/library/ms187449.aspx
    Thanks,
    Sateesh.
    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.

  • How to run Exe file through Sql server agent job

    Hello All
    i have 2 servers 
    1.Application Server
    2.Database server
    Application server has a .exe file so i wanted to run this exe file through SQL server agent job from database server.
    What is the process for run this Exe file 
    Can you plz suggest me step by step process
    Kamal

    While i'm trying to implement this below method
    Step1 : Right Click SQL Server Agent. Select New -> Job. This will open a wizard to schedule a new
    job.
    Step2 : Select Steps from options given on the left side of wizard. This is the main place to set your
    exe\program as a running step. Give some name to this step, Select Operating System (cmdexec) for the Type and give the full path of exe in Text box for Command.
    ex:\\10.11.00.98(your application serverIP)\ch.exe
    Thanks vanchan-Please
    mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers
    I got this below error
    Message
    Executed as user:NJROSJ345\SYSTEM. The process could not be created for step1 of job
    (Reason:Access is Denied)The step failed.
    But i have sys admin rights on the both the servers 
    Kamal

  • Not able to run the SSIS package in SQL Server Agent Job in SQL 2012

    Hi,
    I scheduled a job (SQL SERVER AGENT) which will call my SSIS package. This package will execute 5 packages in loop.
    When I execute this job I am getting error as below
    ============================================================
    Started  : 12:30:19 PM 
    Error  : 2014-01-23 12:30:20.37    
    Code  : 0xC00220EC    
    Source  : Execute Package Task     
    Description : Error 0x80070005. Failed to create an instance of empty child package.
        The Distributed Component Object Model (DCOM) configuration or the installation of SQL Server Integration Services,
        may be corrupted on your machine.  End Error 
    Error  : 2014-01-23 12:30:20.37    
    Code  : 0xC00220DE    
    Source  : Execute Package Task     
    Description : Error 0x80070005 while loading package file "D:\SSIS\RetailMobileApp\Staging_Pkg\stg_Category_Master.dtsx". Access is denied.End Error 
    DTExec  : The package execution returned DTSER_FAILURE (1). 
    Started  : 12:30:19 PM 
    Finished : 12:30:20 PM 
    Elapsed  : 1.123 seconds. 
    The package execution failed. 
    The step failed.
    ============================================================
    In the STEPS I have selected as follows:
    Type  : SQL Server Integration Services Package
    Run as: SQL Server Agent Service Account
    Package Source: File System
    What config I need to check here ? This job is not able to access the package stored in the folder.
    Sridhar

    Thanks for your reply. I had created credentials and used this while creating the Proxy account. With the Proxy account I am able to execute the Job Successfully. Concern here is I used my NT account to create this Proxy. Suppose If I left from the
    current project if some one is coming to this project later they need to change the credential with their NT account and run the JOB? Is this right way or we an create any other account in common? If so how?
    Sridhar

  • SQL server agent job running as Agent Service Account whose service account does not have r/w access but is still able to write?

    Hi. I am newer to SQL server security and am reviewing some of our SQL server's configuration to make sure the services are running under accounts with least privilege.  I have a SQL server 2012 instance whose Agent service is configured to run
    under an AD user account named 'SQLServices'.  The jobs on this server are configured to run as 'SQL server agent service account', which means they should execute as user 'SQLServices'.  The jobs are set up to execute SSIS packages which read and
    write to a database on the same server where the agent job is scheduled and SSIS package installed (all on same server).  The jobs are currently executing without error and are reading writing data correctly.  Upon close examination, it turns out the
    SQLServices account is not assigned to the 'sysadmin' role and had no users mapped to any databases on this server.  How are these jobs working?  I verified in profiler that the login name indeed is 'SqlServices'.  I also verified
    that SQLServices login has no database access by remote-ing onto the server and trying to log into the DB, and access was denied as expected.  According to the literature, the Agent service needs to be a member of 'sysadmin role' but I am reading
    some cases where that is not necessarily the case.  So this is not so concerning.  What is concerning is that the login 'SQLServices' had no access to the databases on that server yet it is reading and writing to the databases as if it does. 
    The only thing I can think of is maybe jobs run as 'SQL server agent service account' on the same server as the databases it r/w to somehow has some kind of default access.  What am I missing here?  Any input would be helpful.

    After 2 days on this forum I found the answer to my own question.  In retrospect, I should have posted this under 'SQL Server Security', but I didn't know it existed.
    The 2 threads below explain that Sql agent actually runs using SID (service) NT SERVICE\SQLSERVERAGENT if you chose that when you installed.  This will automatically create an associated login NT SERVICE\SQLSERVERAGENT in SQL server with sqladmin
    role.  This is the login that Agent uses to connect to the local instance of SQL server.  If you changed to domain account to run the service during install or after using config manager, basically NT SERVICE\SQLSERVERAGENT is still
    used to connect to your local instance behind the scenes (even though you will still see your domain user as account), and the domain account is used to reach outside the server. 
    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/9e6bb2de-8fd0-45de-ab02-d59bbe05f72e/servicedatabase-accounts-nt-servicemssqlserver-nt-servicesqlserveragent-what-are-they-for
    https://social.technet.microsoft.com/Forums/sqlserver/en-US/b83a52fd-fe11-4c28-a27b-88be8ae79f2a/how-do-i-change-sql-server-agent-service-account-to-nt-servicesqlserveragent?forum=sqlsecurity

  • How to stop SQL Server Agent Job if Stored Procedure returns value 0

    I have SQL Server 2012 SSIS.
    I have 2 SSIS packages.
    I have created SQL Server Agent Job for running packages.
    I have created steps. If first step have run succesfully next step is run.
    I have need to add new logic.
    I have validation stored procedure, which validate DB table values and returns 1 or 0.
    I would like to create logic where first of all this SP is runned. Return value of SP determines if steps are run or not.
    I was thinking to use Execute SQL Task for running SP.
    If value 1 is returned, then run rest of Tasks is run.
    If value 0 is returned, what should I do so that Job is stopped? I need assistance! 
    I want current step to stop never moved to next step.
    Is there any SSIS tasks, which can stop the Job?
    Or should I make Step for running validation SP?
    How to do so that if value 0 is returned stop Job.
    Kenny_I

    Please refer the below link:
    http://technet.microsoft.com/en-us/library/aa260308(v=sql.80).aspx
    Please read Remarks carefully!!!
    Remarks
    If a job is currently executing a step of type CmdExec, the process being run (for example, MyProgram.exe) is forced to end prematurely. Premature ending can result in unpredictable behavior such as files in use by the process being held open. Consequently,
    sp_stop_job should be used only in extreme circumstances if the job contains steps of type CmdExec.
    Permissions
    Execute permissions default to the public role in the
    msdb database. A user who can execute this procedure and is a member of the
    sysadmin fixed role can stop any job. A user who is not a member of the
    sysadmin role can use sp_stop_job to stop only the jobs he/she owns.
    When sp_stop_job is invoked by a user who is a member of the
    sysadmin fixed server role, sp_stop_job will be executed under the security context in which the SQL Server service is running. When the user is not a member of the
    sysadmin group, sp_stop_job will impersonate the SQL Server Agent proxy account, which is specified using
    xp_sqlagent_proxy_account. If the proxy account is not available,
    sp_stop_job will fail. This is only true for Microsoft® Windows® NT 4.0 and Windows 2000. On Windows 9.x, there is no impersonation and
    sp_stop_job is always executed under the security context of the Windows 9.x user who started SQL Server.

  • HOw to avoid DeadLocks when you schedule a Sql Server Agent Job and calling SSIS packages

    Hi All,
    I have scheduled 2 packages in in Sql Server Agent jobs .
    First job which is having Package 1 executing at 11 AM and where I am inserting the data in the table.
    Second job which is having Package 2 executing at 12 AM and where I am updating the data in the table based on the first job inserted records.
    When I am executing my first job it taking more time and executing till 12 AM and from 12 AM my job 2 also starting ,so getting deadlocks conflicts because inserting happening from job1 and updating happening from Job 2.
    How to avoid deadlocks and fix the issue.
    Please Suggest .
    Thanks & Regards,
    Anand

    Hi Anand,
    Here is another solution, you can set the Job 2 not to run based on a schedule, and create another SQL Server Agent Job which starts at 12 AM and run with a specified time interval to execute a SQL statement in which you do the following steps:
    1. Get the status information of Job 1 using the statement:
    DECLARE @i int;
    EXEC @i = msdb.dbo.sp_help_job @job_name = ‘Job Name'
    2. If the value of @i is 1 which means the status of job 1 is success and current time is, then start the job 2. So, the statement is as follows:
    IF @I = 1
    EXEC msdb.dbo.sp_start_job @job_name= ‘Job Name’
    Regards,
    Mike Yin
    TechNet Community Support

Maybe you are looking for

  • Fiscal Month/Year Date Calculations

    Hi Gurus, I am trying to create a fiscal year and fiscal month offset using filter advanced SQL in answers. The “Offset” should allow to define a period of time + or – from a given starting point in order to report on a period of time. For example th

  • SQL Server Licensing Query

    Hi Team , I have some queries for MS SQL server , can you please clarify the below points : Can I buy licenses for SQL 2008 R2 or do I need to buy license for MSSQL server 2012 license and then downgrade it? Would there be any additional cost for dow

  • Error in the t.code KKAO

    hi all, i erceive the below error message while using the t.code KKAQ ERROR : The system has determined that the authorizations for displaying the data of WIP calculation regarding authorization objects K_WIP and/or K_TP_VALU are missing. pls tell me

  • Search Method

    Dear all, I am working in ADF 10g (I have a problem when I am creating Search method). I need to make search by using LOV (create 2 LOV list one for month and one for Year) In my DB I have the the date in one column (19-Feb-2009) I make two view obje

  • Setting Build-In/Out markers for multiple animated tracks

    I have built a title that has the the Build-Optional markers so that the user can trim the title without altering the animation timing. However, the title has an additional animation running through the sequence. This means that the Build-In and Out