Creation date based device collections

Ranjithkumar Duraisamy 231 Reputation points
2022-08-18T11:46:00.357+00:00

Hi Team,

I have been trying to create a dynamic collection based on device creation date. But the below query attracts some devices which has 2019 dated as well. Any thing wrong here or any opportunity to improve this?

SELECT
SMS_R_System.ResourceId,
SMS_R_System.ResourceType,
SMS_R_System.Name,
SMS_R_System.SMSUniqueIdentifier,
SMS_R_System.ResourceDomainORWorkgroup,
SMS_R_System.Client
FROM SMS_R_System
WHERE DATEPART(DD, SMS_R_System.CreationDate) <= 3
AND SMS_R_System.operatingSystem LIKE "%Windows Server%"

Microsoft Security | Intune | Configuration Manager | Other
0 comments No comments
{count} votes

6 answers

Sort by: Most helpful
  1. Garth Jones 1,666 Reputation points MVP
    2022-08-18T12:38:19.643+00:00

    Datepart is NOT valid for the Where clause. use getdate and datdiff instead.
    https://learn.microsoft.com/en-us/mem/configmgr/develop/core/understand/extended-wmi-query-language

    2 people found this answer helpful.
    0 comments No comments

  2. CherryZhang-MSFT 6,496 Reputation points
    2022-08-19T06:52:50.547+00:00

    Hi @Alin Martinos ,
    Thanks for your detailed case description.

    As GarthJones-9654 said, I did some test. Below is my test result for your reference.

    WQL Query:
    SELECT
    SMS_R_System.ResourceId,
    SMS_R_System.ResourceType,
    SMS_R_System.Name,
    SMS_R_System.SMSUniqueIdentifier,
    SMS_R_System.ResourceDomainORWorkgroup,
    SMS_R_System.Client,
    SMS_R_System.CreationDate
    FROM SMS_R_System
    WHERE DATEDiff(DD, SMS_R_System.CreationDate, Getdate()) <= 20
    AND SMS_R_System.OperatingSystemNameandVersion LIKE "%Server%"

    232764-1.png

    232746-2.png

    0 comments No comments

  3. Ranjithkumar Duraisamy 231 Reputation points
    2022-08-19T10:17:03.13+00:00

    Thank you so much for both of your input. When try to see the same via Query Design, syntax error pops up. Isn't weird?

    232883-image.png

    0 comments No comments

  4. Garth 5,801 Reputation points
    2022-08-19T10:57:17.007+00:00

    It should be fine. Not all queries work in design viewer. As long as you see request in your collection you are fine.

    0 comments No comments

  5. Ranjithkumar Duraisamy 231 Reputation points
    2022-08-19T11:15:05.173+00:00

    Thank you for clarifying the same.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.