need query help to gather recently used app data


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)

Posted by: Jsaylor 13 years ago
Second Degree Blue Belt
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.

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 13 years ago
Yellow Belt
Thank you very much! I believe that will help us. We're trying it out now, appreciate the response!
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login


This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ