O R G A N I C / F E R T I L I Z E R: sms: maybe you should date your clients? :^)

Feb 1, 2008

sms: maybe you should date your clients? :^)

i don't think it's too much of a stretch or really a broad assumption that any given collection at probably any given site has some amount of stale information.  machines go offline, people go on vacation, machines "mysteriously" drop off the domain...

this tends to come up often so i thought i'd put it out there.  it's all over the place though.  do a search for "sms datediff", "sms getdate", or "sms dateadd".  my guess is the first one will be the most beneficial since it's the one most people use.  if you find that you have too many old machines showing up in your collections, try something like this:

select    SMS_R_System.ResourceID 
from      SMS_R_System inner join SMS_G_System_WORKSTATION_STATUS on
          SMS_G_System_WORKSTATION_STATUS.ResourceID = SMS_R_System.ResourceId
where DATEDIFF(dd,SMS_G_System_WORKSTATION_STATUS.LastHardwareScan,GetDate()) < 14


datediff looks for these parts: what to measure, the starting date, the ending date.  in our evaluation, we're measuring by the day, looking at the lasthardwarescan value and using the current date to check against.  we take that value and check to see if it's less than 14.  if it is, cool.  show it.  if not, drop it.

you can do this in sql, too.  no doubt you want to make your reports not show old crap.  here's an example of what a sql statement would look like:

select distinct
            sys.ad_site_name0 as [Site],
            cs.name0 as [CI Name],
            cs.manufacturer0 as [Manufacturer],
            cs.model0 as [Model],
            se.serialnumber0 as [Serial #]
from  v_GS_COMPUTER_SYSTEM cs
            inner join v_GS_SYSTEM_ENCLOSURE se on cs.resourceid=se.resourceid
            inner join v_R_SYSTEM sys on cs.resourceid=sys.resourceid
            inner join v_GS_WORKSTATION_STATUS ws on cs.resourceid=ws.resourceid
where DATEDIFF(day, ws.lasthwscan, getdate()) < 14