

--  ------------  Generated from [/big2/11.0/Build80_SP24/cxunix/source/CommServer/Db/Sp/JMCheckConflictingVMSelectiveJob.sp] ---------- 

--  +========================================================================+
--  |		 		 Name:  JMCheckConflictingVMSelectiveJob()
--  |				 Description:  Only selective job or streaming job will call this SP - not for snap backup
--  +========================================================================+
-- dataServer_h_rcsid[]="@(#)$Source: /cvs/cvsrepro/GX/vaultcx/Source/CommServer/Db/Sp/JMCheckConflictingVMSelectiveJob.sp,v $ $Id: JMCheckConflictingVMSelectiveJob.sp,v 1.2.10.2 2021/07/13 17:17:10 bzhu Exp $";
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
SET NOCOUNT ON


IF EXISTS (select * from sysobjects where name='JMCheckConflictingVMSelectiveJob')
BEGIN
	print '>>> Drop Stored Procedure: JMCheckConflictingVMSelectiveJob <<<'
	drop procedure JMCheckConflictingVMSelectiveJob
END
IF EXISTS (select * from GxQscripts where name='JMCheckConflictingVMSelectiveJob')
	delete from GxQscripts where name = 'JMCheckConflictingVMSelectiveJob'
GO

IF EXISTS (select * from GXDBVersions where aliasname='JMCheckConflictingVMSelectiveJob')
	delete from GXDBVersions where aliasname = 'JMCheckConflictingVMSelectiveJob'
GO
print '... Creating Procedure: JMCheckConflictingVMSelectiveJob'
GO
SET QUOTED_IDENTIFIER ON
SET NOCOUNT ON
GO
create procedure JMCheckConflictingVMSelectiveJob
  @i_parentJobId integer,
  @i_commCellId integer,
  @i_vmClientId integer
AS
SET NOCOUNT ON
  DECLARE @jobId integer
BEGIN
	DECLARE @parentAppId INT = 0
	DECLARE @vmGuid nvarchar(255) = N''
	-- get VM GUID
	SELECT @vmGuid = P.attrVal
	FROM App_clientProp P WITH (NOLOCK)
	WHERE P.componentNameId = @i_vmClientId
		AND P.attrName = 'Virtual Machine Instance UUID'
		AND P.modified = 0
	-- set parent app id
	SELECT @parentAppId = JBKP.applicationId
	FROM JMBkpJobInfo JBKP WITH (NOLOCK)
	WHERE JBKP.commCellId = @i_commCellId
		AND JBKP.jobId = @i_parentJobId
	-- if there is a VM selective job from vsa parent subclient, then skip current job
	SELECT DISTINCT JBKP.jobId
	FROM JMBkpJobInfo JBKP WITH (NOLOCK)
	WHERE JBKP.applicationId = @parentAppId
		AND JBKP.commcellId = @i_commCellId
		AND JBKP.jobId <> @i_parentJobId
AND EXISTS(SELECT 1 FROM GetJobOptionList(JBKP.jobId, 765158193) WHERE value LIKE '%' + @vmGuid + '%' )
END
GO

IF EXISTS (select * from GxQscripts where name = 'JMCheckConflictingVMSelectiveJob')
	delete from GxQscripts where name = 'JMCheckConflictingVMSelectiveJob'
GO

IF EXISTS (select * from GXDBVersions where aliasname='JMCheckConflictingVMSelectiveJob')
	delete from GXDBVersions where aliasname = 'JMCheckConflictingVMSelectiveJob'
GO

insert into GXDBVersions values(2, 'JMCheckConflictingVMSelectiveJob',  '00010002001000020000', 'JMCheckConflictingVMSelectiveJob', '00010002001000020000')
GO

