tags:

views:

316

answers:

1

WQL (basically SQL for WMI) does not support the TOP keyword the way Sql Server and many other RDBMSs do (though the actual keyword is different sometimes but the concept is implemented.)

Is there a workaround to emulating a SELECT query to behave as though it had a TOP clause that limited the result set?

Or is there some other WQL-specific keyword that works like TOP?

Thanks.

+2  A: 

Nope, there's no way to simulate TOP using WQL alone.

Exception: if you're lucky enough to be querying a WMI class which has ungapped, ascending numeric instance numbers used as keys, then you can use greater-than and less-then comparisons to limit and page through the results.

It's possible that ManagementClass.GetInstances() instead of using a WQL query might allow you to cancel the enumeration midway once you've collected enough instances, and hence avoid paying the CPU and RAM cost of enumerating the whole list at once.

Note that, AFAIK, the CIMV2 WMI provider doesn't natively handle WQL-- instead it simply relies on WMI to enumerate all instances, process the WQL, and filter the results before returning them to the caller. But the expensive part (actually fetching the underlying WMI data) is still done. So I believe there's no efficiency gain to be had (for local WMI queries, that is) by using WQL vs. using using GetInstances() and filtering the results yourself-- and if GetInstances() allows you to cancel midway, then GetInstances() may be much cheaper for long result sets.

Justin Grant
i found this: http://stackoverflow.com/questions/595123/is-there-an-ansi-sql-alternative-to-the-mysql-limit-keyword Any chance that WQL supports one of those "TOP" syntax alternatives from the answer?
Paul Sasik
Nope. WQL does not support this feature.
Justin Grant