Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



dbo.sp_verify_job_identifiers

  No additional text.


Syntax
CREATE PROCEDURE sp_verify_job_identifiers
  @name_of_name_parameter  VARCHAR(60),             -- Eg. '@job_name'
  @name_of_id_parameter    VARCHAR(60),             -- Eg. '@job_id'
  @job_name                sysname          OUTPUT, -- Eg. 'My Job'
  @job_id                  UNIQUEIDENTIFIER OUTPUT,
  @sqlagent_starting_test  VARCHAR(7) = 'TEST',      -- By default we DO want to test if SQLServerAgent is running (caller should specify 'NO_TEST' if not desired)
  @owner_sid                VARBINARY(85) = NULL OUTPUT
AS
BEGIN
  DECLARE @retval         INT
  DECLARE @job_id_as_char VARCHAR(36)

  SET NOCOUNT ON

  -- Remove any leading/trailing spaces from parameters
  SELECT @name_of_name_parameter = LTRIM(RTRIM(@name_of_name_parameter))
  SELECT @name_of_id_parameter   = LTRIM(RTRIM(@name_of_id_parameter))
  SELECT @job_name               = LTRIM(RTRIM(@job_name))

  IF (@job_name = N'') SELECT @job_name = NULL

  IF ((@job_name IS NULL)     AND (@job_id IS NULL)) OR
     ((@job_name IS NOT NULL) AND (@job_id IS NOT NULL))
  BEGIN
    RAISERROR(14294, -1, -1, @name_of_id_parameter, @name_of_name_parameter)
    RETURN(1) -- Failure
  END

  -- Check job id
  IF (@job_id IS NOT NULL)
  BEGIN
    SELECT @job_name = name,
           @owner_sid = owner_sid
    FROM msdb.dbo.sysjobs_view
    WHERE (job_id = @job_id)

    -- the view would take care of all the permissions issues.
    IF (@job_name IS NULL)
    BEGIN
      SELECT @job_id_as_char = CONVERT(VARCHAR(36), @job_id)
      RAISERROR(14262, -1, -1, '@job_id', @job_id_as_char)
      RETURN(1) -- Failure
    END
  END
  ELSE
  -- Check job name
  IF (@job_name IS NOT NULL)
  BEGIN
    -- Check if the job name is ambiguous
    IF ((SELECT COUNT(*)
         FROM msdb.dbo.sysjobs_view
         WHERE (name = @job_name)) > 1)
    BEGIN
      RAISERROR(14293, -1, -1, @job_name, @name_of_id_parameter, @name_of_name_parameter)
      RETURN(1) -- Failure
    END

    -- The name is not ambiguous, so get the corresponding job_id (if the job exists)
    SELECT @job_id = job_id,
           @owner_sid = owner_sid
    FROM msdb.dbo.sysjobs_view
    WHERE (name = @job_name)

    -- the view would take care of all the permissions issues.
    IF (@job_id IS NULL)
    BEGIN
      RAISERROR(14262, -1, -1, '@job_name', @job_name)
      RETURN(1) -- Failure
    END
  END

  IF (@sqlagent_starting_test = 'TEST')
  BEGIN
    -- Finally, check if SQLServerAgent is in the process of starting and if so prevent the
    -- calling SP from running
    EXECUTE @retval = msdb.dbo.sp_is_sqlagent_starting
    IF (@retval <> 0)
      RETURN(1) -- Failure
  END

  RETURN(0) -- Success
END

 
Last revision 2008RTM
See also

  sp_addmergepullsubscription_agent (Procedure)
sp_addpullsubscription_agent (Procedure)
sp_add_jobschedule (Procedure)
sp_add_jobserver (Procedure)
sp_add_jobstep_internal (Procedure)
sp_apply_job_to_targets (Procedure)
sp_attach_schedule (Procedure)
sp_delete_job (Procedure)
sp_delete_jobschedule (Procedure)
sp_delete_jobserver (Procedure)
sp_delete_jobstep (Procedure)
sp_delete_jobsteplog (Procedure)
sp_detach_schedule (Procedure)
sp_get_chunked_jobstep_params (Procedure)
sp_get_job_alerts (Procedure)
sp_help_downloadlist (Procedure)
sp_help_job (Procedure)
sp_help_jobactivity (Procedure)
sp_help_jobhistory (Procedure)
sp_help_jobschedule (Procedure)
sp_help_jobserver (Procedure)
sp_help_jobstep (Procedure)
sp_help_jobsteplog (Procedure)
sp_MSadd_distribution_agent (Procedure)
sp_MSadd_logreader_agent (Procedure)
sp_MSadd_merge_agent (Procedure)
sp_MSadd_qreader_agent (Procedure)
sp_MSadd_snapshot_agent (Procedure)
sp_multi_server_job_summary (Procedure)
sp_purge_jobhistory (Procedure)
sp_start_job (Procedure)
sp_stop_job (Procedure)
sp_update_job (Procedure)
sp_update_jobschedule (Procedure)
sp_update_jobstep (Procedure)
sp_verify_alert (Procedure)
       



News

  Query a named instance
Sybase+ASE+silent+install
SQL 2008 R2
Deprecated procedures in SQL2008
Reporting Services item-level role definitions
Create all your missing indexes
Converting datetime field
Start MSSQL Server Profiler at time
Replicating MSSQL Server views
Exploring Microsoft Sharepoint
The OLE DB provider "SQLNCLI10" for linked server indicates.
Mobile solar charger
Oracle to SQL Server replication
Cannot insert the value NULL into column
Undocumented Microsoft SQL Server 2008
VMware
Zoekmachine optimalisatie
SQL Servers hidden objects
FckEditor
Flash in Ajax
De hype die AJAX heet
Barcode scannen
MySQL; Gratis, makkelijk en snel!
PHP
sIFR; de combinatie tussen HTML en Flash