Video Screencast Help
Search Video Help Close Back
to help
Not able to make it to Vision this year? Get a sampling in the Best of Vision on Demand group.

SQL Policy to Filter relationship

Created: 20 Jul 2010 | 3 comments
Bondo's picture
0 0 Votes
Login to vote

Has anyone run across a table(s) or view(s) in SQL that can link a filter to what Policies it is referenced by? 

I have tried the following but the problem with the view vPolicyAppliesToResource is that it only works if there is at least one machine in the filter:

Any ideas would be greatly appreciated.

------Step 1-----Returns ResourceTargetFilter Guid

SELECT [ParentItemGuid]

FROM [vItemReference]

where [ChildItemGuid] = 'c8edf1e4-6baf-484c-8129-5ed8604ed43b' -- Software X Filter Guid

-----Step 2-----Use ResourceTargetFilter GIUD to Get Install Policy

select * from vPolicyAppliesToResource

where ResourceTargetGuid = '88500DE4-2348-4A8C-9E4F-4621DC3D4D26'  -- ResourceTargetFilter

 

Comments

Rhys Paterson's picture
16
Nov
2010
0 Votes 0
Login to vote

Anyone have an update on this?

Basically, I just want a list of all software policies assigned to a filter.

You can do this manually the long way by running these four queries:

USE Symantec_CMDB 
 
-- 1) Get the guid of the filter we are looking at
 
SELECT  vi.[Guid]
 
FROM vItem vi
 
WHERE vi.Name = 'YOUR FILTER NAME'
 
-- 2) Get the ParentItemGuid from vItemReference using the resolved Guid
 
SELECT vir.[ParentItemGuid]
 
FROM vItemReference vir
 
WHERE vir.[ChildItemGuid] = '77210836-CD27-4681-B089-A26FCD7A6356' -- Software X Filter Guid
 
-- 3) Get the PolicyGuid from vPolicyAppliesToResource using the resolved ParentItemGuid
 
SELECT DISTINCT vp.[PolicyGuid] 
 
FROM vPolicyAppliesToResource vp
 
WHERE vp.[ResourceTargetGuid] = 'AC1A648A-E729-420A-8C26-0005D78CA4B9'
 
-- 4) Get the name of the resource using the resolved PolicyGuid
 
SELECT vi.[Name] 
 
FROM vItem vi 

WHERE vi.[Guid] = 'C4C3A54E-82AB-4BB9-A306-886C9F541885'

I'm no SQL genius so surely there is a better way to do this.

Any help would be very much appreciated.

Cheers,

Rhys

Bondo's picture
18
Nov
2010
1 Vote +1
Login to vote

Answer from another non SQL genius

Hey Rhys,

Give this a try.  It may not be the most efficient way to do this but it works.  I had to do something similar for a workflow I did.  I baiscally started with the step 4 query and worked my way back to step 1 replacing the Guid with the sql query in the previous step.  Let me know if it works out.

Good Luck!

SELECT vi.[Name]

 FROM vItem vi

WHERE vi.[Guid] = (SELECT DISTINCT vp.[PolicyGuid]

 FROM vPolicyAppliesToResource vp

 WHERE vp.[ResourceTargetGuid] = (SELECT vir.[ParentItemGuid]

 FROM vItemReference vir

 WHERE vir.[ChildItemGuid] = (SELECT vi.[Guid]

 FROM vItem vi

 WHERE vi.Name = 'YOUR FILTER NAME')))

Rhys Paterson's picture
18
Nov
2010
0 Votes 0
Login to vote

Thanks Bondo!

That works really well.

Only problem is if there is more than one software resource assigned to the filter, I get the following error:

 Msg 512, Level 16, State 1, Line 3

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
Most of our filters have more than one software resource assigned to it. The error is understandable, but I've no idea how to work around it.
 
I assume some kind of FOR loop?
 
Any suggestions?