I think:
exec spLoadItemAppliesTo @itemGuid='0080DB39-521D-4373-B244-7B4E55E904F6'
Is run first, using the GUID of the Policy, which returns the list of GUID of all the targets:
ResourceTargetGuid
AF5FFD9B-33DE-47C6-8386-C2E9F86CE219
which then has:
exec spGetResourceTargetsMembershipScopedWithType @targetGuids=N'af5ffd9b-33de-47c6-8386-c2e9f86ce219',@trustees=N'{2E1F478A-4986-4223-9D1E-B5920A63AB41},{582029E2-FC5B-4717-8808-B80D6EF0FD67},{AB2BC4AA-6123-4FD7-8E37-45C492784FF2},{B760E9A9-E4DB-404C-A93F-AEA51754AA4F}',@resourceTypeGuid='493435F7-3B17-4C4C-B07F-C23E7AB7781F'
run against each GUID returned above.
spLoadItemAppliesTo:
USE [Symantec_CMDB]
GO
/****** Object: StoredProcedure [dbo].[spLoadItemAppliesTo] Script Date: 21/10/2015 10:57:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spLoadItemAppliesTo]
@itemGuid uniqueidentifier
AS
SELECT iat.ResourceTargetGuid
FROM ItemAppliesTo iat
INNER JOIN vNonResourceItem vi
ON iat.ResourceTargetGuid = vi.Guid
WHERE iat.ItemGuid = @itemGuid
spGetResourceTargetsMembershipScopedWithType
USE [Symantec_CMDB]
GO
/****** Object: StoredProcedure [dbo].[spGetResourceTargetsMembershipScopedWithType] Script Date: 21/10/2015 10:59:01 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spGetResourceTargetsMembershipScopedWithType]
@targetGuids NVARCHAR( MAX ),
@trustees NVARCHAR( MAX ),
@resourceTypeGuid UNIQUEIDENTIFIER = NULL
AS
BEGIN
SET NOCOUNT ON;
DECLARE @targetGuidsLocal NVARCHAR( MAX )
DECLARE @trusteesLocal NVARCHAR( MAX )
SET @targetGuidsLocal = @targetGuids
SET @trusteesLocal = @trustees
DECLARE @targetGuidsTable TABLE ( [Guid] UNIQUEIDENTIFIER PRIMARY KEY )
INSERT INTO @targetGuidsTable ( [Guid] )
SELECT ui FROM fnListToTableUniqueIdentifier( @targetGuidsLocal, DEFAULT )
IF ( @resourceTypeGuid IS NULL )
BEGIN
SELECT DISTINCT rtmc.ResourceTargetGuid, rtmc.ResourceGuid, irt.ResourceTypeGuid, '' AS 'Domain'
FROM ResourceTargetMembershipCache rtmc
INNER JOIN @targetGuidsTable tgt
ON rtmc.ResourceTargetGuid = tgt.[Guid]
INNER JOIN
(
SELECT ResourceGuid
FROM ScopeMembership
WHERE ScopeCollectionGuid IN
(
SELECT * FROM dbo.fnGetTrusteeScopeCollections( @trustees )
)
) a ON rtmc.ResourceGuid = a.ResourceGuid
INNER JOIN ItemResourceType irt ON rtmc.ResourceGuid = irt.Guid
END
ELSE
BEGIN
IF ( @resourceTypeGuid = '493435F7-3B17-4C4C-B07F-C23E7AB7781F' )
BEGIN
SELECT DISTINCT rtmc.ResourceTargetGuid, rtmc.ResourceGuid, irt.ResourceTypeGuid, ISNULL( id.Domain, '' ) AS 'Domain'
FROM ResourceTargetMembershipCache rtmc
INNER JOIN @targetGuidsTable tgt
ON rtmc.ResourceTargetGuid = tgt.[Guid]
INNER JOIN
(
SELECT ResourceGuid
FROM ScopeMembership
WHERE ScopeCollectionGuid IN
(
SELECT * FROM dbo.fnGetTrusteeScopeCollections( @trustees )
)
) a ON rtmc.ResourceGuid = a.ResourceGuid
INNER JOIN ItemResourceType irt ON rtmc.ResourceGuid = irt.Guid
INNER JOIN ResourceTypeHierarchy rth ON irt.ResourceTypeGuid = rth.ResourceTypeGuid
LEFT JOIN Inv_AeX_AC_Identification id ON irt.Guid = id._ResourceGuid
WHERE rth.BaseResourceTypeGuid = @resourceTypeGuid
END
ELSE
BEGIN
IF ( @resourceTypeGuid = 'FD864F19-4437-4a4f-8709-58EB5E3AE0A4' )
BEGIN
SELECT DISTINCT rtmc.ResourceTargetGuid, rtmc.ResourceGuid, irt.ResourceTypeGuid, ISNULL( id.Domain, '' ) AS 'Domain'
FROM ResourceTargetMembershipCache rtmc
INNER JOIN @targetGuidsTable tgt
ON rtmc.ResourceTargetGuid = tgt.[Guid]
INNER JOIN
(
SELECT ResourceGuid
FROM ScopeMembership
WHERE ScopeCollectionGuid IN
(
SELECT * FROM dbo.fnGetTrusteeScopeCollections( @trustees )
)
) a ON rtmc.ResourceGuid = a.ResourceGuid
INNER JOIN ItemResourceType irt ON rtmc.ResourceGuid = irt.Guid
INNER JOIN ResourceTypeHierarchy rth ON irt.ResourceTypeGuid = rth.ResourceTypeGuid
LEFT JOIN Inv_Global_Windows_Users id ON irt.Guid = id._ResourceGuid
WHERE rth.BaseResourceTypeGuid = @resourceTypeGuid
END
ELSE
BEGIN
SELECT DISTINCT rtmc.ResourceTargetGuid, rtmc.ResourceGuid, irt.ResourceTypeGuid, '' AS 'Domain'
FROM ResourceTargetMembershipCache rtmc
INNER JOIN @targetGuidsTable tgt
ON rtmc.ResourceTargetGuid = tgt.[Guid]
INNER JOIN
(
SELECT ResourceGuid
FROM ScopeMembership
WHERE ScopeCollectionGuid IN
(
SELECT * FROM dbo.fnGetTrusteeScopeCollections( @trustees )
)
) a ON rtmc.ResourceGuid = a.ResourceGuid
INNER JOIN ItemResourceType irt ON rtmc.ResourceGuid = irt.Guid
INNER JOIN ResourceTypeHierarchy rth ON irt.ResourceTypeGuid = rth.ResourceTypeGuid
WHERE rth.BaseResourceTypeGuid = @resourceTypeGuid
END
END
END
END