SCCM 2012 Database Query: Office 2010 Service Packs

I need to find out how many computers in the network are running Office 2010 and which service pack.

SCCM 2012
SQL 2008

Software inventory is turned on, and I can see that there are approx 1100 systems with Office 2012, but it doesn't show the service pack information.

I've run the following query directly on the database but so far its been "debugging query" for over 30 minutes

SELECT arp.DisplayName0, case
when arp.version0 LIKE '11.0.6361.0' then 'SP1' when arp.version0 LIKE '11.0.7969.0' then 'SP2' when arp.version0 LIKE '11.0.8173.0' then 'SP3' when arp.version0 LIKE '12.0.6215.1000' then 'SP1' when arp.version0 LIKE '12.0.6425.1000' then 'SP2' when arp.version0 LIKE '12.0.6612.1000' then 'SP3' when arp.version0 LIKE '14.0.6029.1000' then 'SP1'
else ''
end as 'Service Pack', arp.Version0, Count(DISTINCT v_r_system.resourceid) AS 'Count'
FROM v_ADD_REMOVE_PROGRAMS arp, v_r_system, V_RA_System_SMSInstalledSites ASSG
WHERE ARP.resourceid = v_r_system.resourceid and v_r_system.resourceid = assg.resourceid and
(arp.displayname0 like '%Microsoft Office%edition%' or arp.displayname0 like '%Microsoft Office Standard 2007%' or arp.displayname0 like '%Microsoft Office Enterprise 2007%' or arp.displayname0 like '%Microsoft Office Professional%2007%' or arp.displayname0 like '%Microsoft Office Standard 2010%' or arp.displayname0 like '%Microsoft Office Enterprise 2010%' or arp.displayname0 like '%Microsoft Office Professional%2010%' or arp.displayname0 like 'Microsoft Office 2000%' or arp.displayname0 like 'Microsoft Office XP%')and arp.displayname0 not like '%update%' and arp.displayname0 not like '%Microsoft Office XP Web Components' and v_r_system.operating_system_name_and0 not like '%server%' and (InstallDate0 not like 'NULL')
group BY arp.DisplayName0, arp.version0
ORDER BY arp.DisplayName0, arp.version0

I'm not surprised that it's taking that long. With all those LIKE % and OR this query shouldn't has a good performance for sure.
Check if this query it's somehow faster:

SELECT arp.DisplayName0, case arp.version0 when '11.0.6361.0' then 'SP1' when '11.0.7969.0' then 'SP2' when '11.0.8173.0' then 'SP3' when '12.0.6215.1000' then 'SP1' when '12.0.6425.1000' then 'SP2' when '12.0.6612.1000' then 'SP3' when '14.0.6029.1000' then 'SP1' else '' end as 'Service Pack', arp.Version0, Count(DISTINCT v_r_system.resourceid) AS 'Count' FROM v_ADD_REMOVE_PROGRAMS arp, INNER JOIN v_r_system ON ARP.resourceid = v_r_system.resourceid INNER JOIN V_RA_System_SMSInstalledSites ASSG ON v_r_system.resourceid = assg.resourceid WHERE arp.displayname0 like '%Microsoft Office%' and arp.displayname0 not like '%update%' and arp.displayname0 not like '%Microsoft Office XP Web Components' and v_r_system.operating_system_name_and0 not like '%server%' and (InstallDate0 not like 'NULL') GROUP BY arp.DisplayName0, arp.version0 ORDER BY arp.DisplayName0, arp.version0

SELECT arp.DisplayName0, case arp.version0 when '11.0.6361.0' then 'SP1' when '11.0.7969.0' then 'SP2' when '11.0.8173.0' then 'SP3' when '12.0.6215.1000' then 'SP1' when '12.0.6425.1000' then 'SP2' when '12.0.6612.1000' then 'SP3' when '14.0.6029.1000' then 'SP1' else '' end as 'Service Pack', arp.Version0, Count(DISTINCT v_r_system.resourceid) AS 'Count' FROM v_ADD_REMOVE_PROGRAMS arp INNER JOIN v_r_system ON ARP.resourceid = v_r_system.resourceid INNER JOIN V_RA_System_SMSInstalledSites ASSG ON v_r_system.resourceid = assg.resourceid WHERE arp.displayname0 like '%Microsoft Office%' and arp.displayname0 not like '%update%' and arp.displayname0 not like '%Microsoft Office XP Web Components' and v_r_system.operating_system_name_and0 not like '%server%' and (InstallDate0 not like 'NULL') GROUP BY arp.DisplayName0, arp.version0 ORDER BY arp.DisplayName0, arp.version0

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…

In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…