SQL SCCM Query: howto limit collection

Hi,

Got this SQL query on SCCM, how do I limit the query to a specific collection?

SELECT
v_R_System.Name0
as
'Computer Name',

v_GS_OPERATING_SYSTEM.Caption0
as
'Operating System',

v_GS_AntimalwareHealthStatus.LastQuickScanDateTimeStart,
v_GS_AntimalwareHealthStatus.LastQuickScanDateTimeEnd,
v_GS_AntimalwareHealthStatus.LastFullScanDateTimeStart,
v_GS_AntimalwareHealthStatus.LastFullScanDateTimeEnd,

v_GS_AntimalwareHealthStatus.LastQuickScanAge
as 'Days since last quick scan',

v_GS_AntimalwareHealthStatus.LastFullScanAge
as 'Days since last full scan',

v_GS_AntimalwareHealthStatus.EngineVersion
as 'EngineVersion'
     
FROM

v_GS_AntimalwareHealthStatus
INNER JOIN

v_R_System ON v_GS_AntimalwareHealthStatus.ResourceID =
v_R_System.ResourceID INNER JOIN
v_GS_OPERATING_SYSTEM ON v_R_System.ResourceID = v_GS_OPERATING_SYSTEM.ResourceID

J.
janhoedtAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pawan KumarDatabase ExpertCommented:
Which database are you using ? How many rows do you want to limit?
0
NEnterprise Systems EngineerCommented:
Hello.

If you join v_FullCollectionMembership on v_r_system,id = v_fullcollectionmembership.resourceID

you could add

'where v_fullcollectionmembership.CollectionID=@CollID'

That should prompt you to input a collection ID to run the query on.
1
janhoedtAuthor Commented:
Thanks! However, I do not want to prompt for a collection ID, I would like to set it.
F.e. collectionID = '123456'

I'm pretty new to queries, how/where do I add the values you mention to my query?
0
NEnterprise Systems EngineerCommented:
In that case, try the following:

SELECT
v_R_System.Name0
as
'Computer Name',

v_GS_OPERATING_SYSTEM.Caption0
as
'Operating System',

v_GS_AntimalwareHealthStatus.LastQuickScanDateTimeStart,
v_GS_AntimalwareHealthStatus.LastQuickScanDateTimeEnd,
v_GS_AntimalwareHealthStatus.LastFullScanDateTimeStart,
v_GS_AntimalwareHealthStatus.LastFullScanDateTimeEnd,

v_GS_AntimalwareHealthStatus.LastQuickScanAge
as 'Days since last quick scan',

v_GS_AntimalwareHealthStatus.LastFullScanAge
as 'Days since last full scan',

v_GS_AntimalwareHealthStatus.EngineVersion
as 'EngineVersion'
     
FROM

v_GS_AntimalwareHealthStatus
INNER JOIN

v_R_System ON v_GS_AntimalwareHealthStatus.ResourceID =
v_R_System.ResourceID INNER JOIN
v_GS_OPERATING_SYSTEM ON v_R_System.ResourceID = v_GS_OPERATING_SYSTEM.ResourceID JOIN v_fullCollectionMembership on v_R_System.REsourceID = V_FullCollectionMembership.ResourceID

WHERE

v_fullcollectionmembership.collectionID = '123456'
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
janhoedtAuthor Commented:
Great, thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.