求助:修改SQL查询以获取计算机中软件的安装日期
Alright, let's tackle this since it looks like you're querying a Configuration Manager (SCCM) database based on the tables/functions you're referencing!
To pull in the installation date for each software product, you'll need to use the InstallDate0 field—this is the standard field in SCCM's inventory views that stores software installation dates. Most often, this field is stored as a yyyymmdd formatted string, so we'll add a conversion to make it a readable date type too.
Here's your modified query (note I fixed a likely typo in the domain/workgroup field name):
SELECT DISTINCT SYS.Netbios_Name0, SYS.Resource_Domain_OR_Workgr0, -- Corrected typo from Rsqlesource_Domain_OR_Workgr0 SP.CompanyName, SP.ProductName, SP.ProductVersion, -- Convert yyyymmdd string to a proper date format, handle nulls/invalid values CASE WHEN SP.InstallDate0 IS NOT NULL AND LEN(SP.InstallDate0) = 8 THEN CONVERT(DATE, SP.InstallDate0, 112) ELSE NULL END AS InstallDate FROM fn_rbac_Add_Remove_Programs(@UserSIDs) SP -- Adjust the fn_ function if you're using 64-bit programs (fn_rbac_Add_Remove_Programs64) JOIN v_R_System SYS ON SP.ResourceID = SYS.ResourceID
A few key notes:
- If you're targeting 64-bit installed programs specifically, swap
fn_rbac_Add_Remove_Programswithfn_rbac_Add_Remove_Programs64—theInstallDate0field exists in both views. - The
CASEstatement ensures we only convert validyyyymmddstrings to dates, avoiding errors from null or malformed values in the inventory data. - If you don't need the date conversion (e.g., you're okay with the raw
yyyymmddstring), you can simplify it to justSP.InstallDate0 AS InstallDate.
内容的提问来源于stack exchange,提问作者Isma Isma
相关产品推荐
相关产品推荐

