select distinct v1.name 'Machine Name', v1.[user] 'Primary User', CASE
When v1.Guid in (select distinct v1.guid from vComputer v1
inner join Inv_AddRemoveProgram t1 on v1.Guid = t1._ResourceGuid
inner join Inv_OfficeSuiteVersions3 t2 on v1.guid = t2._ResourceGuid
where t1.DisplayName = 'Microsoft Office Professional Plus 2007' and t1.InstallFlag = '1'
and t2.Outlook2007Ver <> 'Not Present')
Then 'Microsoft Office Professional Plus 2007'
When v1.Guid in (select distinct v1.guid from vComputer v1
inner join Inv_AddRemoveProgram t1 on v1.Guid = t1._ResourceGuid
inner join Inv_OfficeSuiteVersions3 t2 on v1.guid = t2._ResourceGuid
where t1.DisplayName = 'Microsoft Office Professional Plus 2010' and t1.InstallFlag = '1'
and t2.Outlook2010Ver <> 'Not Present')
Then 'Microsoft Office Professional Plus 2010'
When v1.Guid in (select distinct v1.guid from vComputer v1
inner join Inv_AddRemoveProgram t1 on v1.Guid = t1._ResourceGuid
inner join Inv_OfficeSuiteVersions4 t2 on v1.guid = t2._ResourceGuid
where t1.DisplayName = 'Microsoft Office Professional Plus 2013' and t1.InstallFlag = '1'
and t2.Outlook2013Ver <> 'Not Present')
Then 'Microsoft Office Professional Plus 2013'
When v1.Guid in (select distinct v1.guid from vComputer v1
inner join Inv_AddRemoveProgram t1 on v1.Guid = t1._ResourceGuid
inner join Inv_OfficeSuiteVersions5 t2 on v1.guid = t2._ResourceGuid
where t1.DisplayName like 'Microsoft Office 365 ProPlus%' and t1.InstallFlag = '1'
and Outlook2016Ver <> 'Not Present')
Then 'Microsoft Office 365 ProPlus'
End [Office Version], v2.[Location by Subnet] 'Location'
from vComputer v1
inner join vcomputerlocations v2 on v1.Guid = v2.Guid
and v1.Name like 'USSD%'
and v1.Guid not in (select Guid from CollectionMembership where FilterName = 'Software Delivery Exclusions')
or v1.Name like 'USSF%'
and v1.Guid not in (select Guid from CollectionMembership where FilterName = 'Software Delivery Exclusions')
or v1.Name like 'USSEA%'
and v1.Guid not in (select Guid from CollectionMembership where FilterName = 'Software Delivery Exclusions')
or v1.Name like 'USBES%'
and v1.Guid not in (select Guid from CollectionMembership where FilterName = 'Software Delivery Exclusions')
or v1.Name like 'USCAM%'
and v1.Guid not in (select Guid from CollectionMembership where FilterName = 'Software Delivery Exclusions')
order by 3,4,1
質問する
65 次
2 に答える
0
アプリケーションで必要な場合は、クエリの末尾から order by を削除して並べ替えます。
結合でインデックスを使用できないため、可能であればこのクエリを書き直す必要があります -> 「USSF%」などのフィルタを使用する場合、SQL エンジンはインデックスを使用できません。
- ない場合は、FilterName にインデックスを作成します。
于 2016-08-09T15:33:57.590 に答える
0
繰り返し操作に共通テーブル式、一時テーブル、またはテーブル変数を使用することを検討し、さまざまな Guid が主キーであると想定して、表示またはフィルター名の列ではなく、それらの値を使用して選択してみてください。
おそらくこのようなもの:
WITH a AS
(
SELECT v1.Guid, v1.Name, v1.[user], t1.DisplayName from vComputer v1
INNER JOIN Inv_AddRemoveProgram t1 on v1.Guid = t1._ResourceGuid
INNER JOIN Inv_OfficeSuiteVersions3 t2 on v1.Guid = t2._ResourceGuid
WHERE t1.InstallFlag = '1'
AND
(t1.PrimaryKey = '2007 PrimaryKey Value' AND t2.Outlook2007Ver <> 'Not Present')
OR
((t1.PrimaryKey = '2010 PrimaryKey Value' AND t2.Outlook2010Ver <> 'Not Present') --etc etc
),
b AS
(
SELECT Guid FROM CollectionMembership WHERE FilterName = 'Software Delivery Exclusions'
) -- would be better to search by primary key
SELECT a.*, v2.[Location by Subnet]
FROM a INNER JOIN vcomputerlocations v2 on a.Guid = v2.Guid
LEFT JOIN b ON a.Guid = b.Guid
WHERE b.Guid IS NULL
完璧ではないかもしれませんが、理解していただければ幸いです
于 2016-08-09T15:46:24.920 に答える