need query help to gather recently used app data
Hello!
I'm in the process of working a project where we want to uninstall a specific piece of sw if it has not been used in the last 180 days. I've got a pretty slick collection set created but I'm missing something major in the query that we've written... hoping for some suggestions.
What I've done so far:
1) created collections named by the spec software code of the sw in question (example: Microsoft Office Visio 2007 Standard Edition)
2) membership to this collection is written by query below...
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 inner join SMS_G_System_INSTALLED_SOFTWARE on SMS_G_System_INSTALLED_SOFTWARE.ResourceID = SMS_R_System.ResourceId inner join SMS_G_System_CCM_RECENTLY_USED_APPS on SMS_G_System_CCM_RECENTLY_USED_APPS.ResourceId = SMS_R_System.ResourceId where SMS_G_System_INSTALLED_SOFTWARE.SoftwareCode = "{91120000-0053-0000-0000-0000000ff1ce}" and SMS_G_System_CCM_RECENTLY_USED_APPS.LastUsedTime > "4/1/2010 12:00:00 am"
Query appears to be pulling system names no problem by the software code installed... problem is it doesn't seem to be pulling the recently used info... and yet another issue w/our query is that we don't want to have to type the date in... we'd like it to be a generic 180 days from last use.... this way we could keep an uninstall advertisement set to the collection that the query creates... does that make sense?
Thank you for your time and any suggestions you may have!
I'm in the process of working a project where we want to uninstall a specific piece of sw if it has not been used in the last 180 days. I've got a pretty slick collection set created but I'm missing something major in the query that we've written... hoping for some suggestions.
What I've done so far:
1) created collections named by the spec software code of the sw in question (example: Microsoft Office Visio 2007 Standard Edition)
2) membership to this collection is written by query below...
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 inner join SMS_G_System_INSTALLED_SOFTWARE on SMS_G_System_INSTALLED_SOFTWARE.ResourceID = SMS_R_System.ResourceId inner join SMS_G_System_CCM_RECENTLY_USED_APPS on SMS_G_System_CCM_RECENTLY_USED_APPS.ResourceId = SMS_R_System.ResourceId where SMS_G_System_INSTALLED_SOFTWARE.SoftwareCode = "{91120000-0053-0000-0000-0000000ff1ce}" and SMS_G_System_CCM_RECENTLY_USED_APPS.LastUsedTime > "4/1/2010 12:00:00 am"
Query appears to be pulling system names no problem by the software code installed... problem is it doesn't seem to be pulling the recently used info... and yet another issue w/our query is that we don't want to have to type the date in... we'd like it to be a generic 180 days from last use.... this way we could keep an uninstall advertisement set to the collection that the query creates... does that make sense?
Thank you for your time and any suggestions you may have!
0 Comments
[ + ] Show comments
Answers (2)
Please log in to answer
Posted by:
Jsaylor
14 years ago
Your date format appears to be a bit off, SQL stores dates in a very specific couple of formats, and in v_GS_CCM_RECENTLY_USED_APPS.lastusedtime0, it's in DATETIME, which looks like this:
So your date, "4/1/2010 12:00:00 am" should actually look like this: "2010-04-01 00:00:00"
With that out of the way, I think what you might be looking for is a little more fancy from the SQL side of things. So rather than use hard dates, you could try using the datediff and getdate functions to give you a comparitive number between the current date and whatever column value you're trying to use. I'll run through a quick example, and you can see if you can adapt it to your purposes.
That condition will evaluate to true for anything that's less than six months old. So we're using datediff(), telling it to return the number of months between the two dates ("mm") then giving it a start date (SMS_G_SYSTEM_CCM_RECENTLY_USED_APPS.lastusedtime0), then giving it an end date of today using getdate(), and finally comparing the result of the datediff to the static number 6.
YYYY-MM-DD HH:MM:SS
So your date, "4/1/2010 12:00:00 am" should actually look like this: "2010-04-01 00:00:00"
With that out of the way, I think what you might be looking for is a little more fancy from the SQL side of things. So rather than use hard dates, you could try using the datediff and getdate functions to give you a comparitive number between the current date and whatever column value you're trying to use. I'll run through a quick example, and you can see if you can adapt it to your purposes.
datediff(mm,SMS_G_SYSTEM_CCM_RECENTLY_USED_APPS.lastusedtime0,getdate()) < 6
That condition will evaluate to true for anything that's less than six months old. So we're using datediff(), telling it to return the number of months between the two dates ("mm") then giving it a start date (SMS_G_SYSTEM_CCM_RECENTLY_USED_APPS.lastusedtime0), then giving it an end date of today using getdate(), and finally comparing the result of the datediff to the static number 6.
Posted by:
CarrieD
14 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.