Useful SQL Queries

Useful SQL Queries

Figured I would share some custom reporting we did to better track our tickets.    

This query isolates just the closing comments that a user leaves upon closing a ticket.

  1. select b.workorderid as "Ticket #", d.first_name as "Submitter", e.first_name as "Tech", LONGTODATE(b.CompletedTime) as "Closed On", a.close_comments as "Comments" from WorkOrderStates a, WorkOrder b, SDUser c, AaaUser d, AAAUser e where ((a.workorderid = b.workorderid) and (b.requesterid  = c.userid) and (c.userid = d.user_id) and (a.ownerid = e.user_id)) AND a.close_comments <> "" AND a.close_comments <> "Aged Request was Closed." order by 1 desc
This next query is what we use for a quick glace asset tag database with S/N's.

  1. SELECT aaaUser.FIRST_NAME "User",aaaUser.FIRST_NAME "User",productType.COMPONENTTYPENAME "Product Type",product.COMPONENTNAME "Product",resource.RESOURCENAME "Resource Name",resource.SERIALNO "Serial Number",resource.ASSETTAG "Asset Tag",systemInfo.SERVICETAG "Service Tag" FROM Resources resource LEFT JOIN ComponentDefinition product ON resource.COMPONENTID=product.COMPONENTID LEFT JOIN ComponentType productType ON product.COMPONENTTYPEID=productType.COMPONENTTYPEID LEFT JOIN ResourceOwner rOwner ON resource.RESOURCEID=rOwner.RESOURCEID LEFT JOIN ResourceAssociation rToAsset ON rOwner.RESOURCEOWNERID=rToAsset.RESOURCEOWNERID LEFT JOIN SDUser sdUser ON rOwner.USERID=sdUser.USERID LEFT JOIN AaaUser aaaUser ON sdUser.USERID=aaaUser.USER_ID LEFT JOIN SystemInfo systemInfo ON resource.resourceid=SystemInfo.workstationid WHERE  ((((((productType.COMPONENTTYPENAME = 'Headsets') OR (productType.COMPONENTTYPENAME = 'Monitors')) OR (productType.COMPONENTTYPENAME = 'Printer')) OR (productType.COMPONENTTYPENAME = 'Workstation')) OR (productType.COMPONENTTYPENAME = 'Scanner')) AND (aaaUser.FIRST_NAME IS NOT NULL))  ORDER BY 1, 3

                  New to ADSelfService Plus?