Query to get Request Details with Group change info and Technician Timespent info

Query to get Request Details with Group change info and Technician Timespent info

Build: 10609
Database: MSSQL

OUTPUT :





SELECT "wo"."WORKORDERID" AS "Request ID",
 LONGTODATE("wo"."CREATEDTIME") AS "Created Time",
  LONGTODATE("wo"."RESOLVEDTIME") AS "Resolved Time",
  "cri"."FIRST_NAME" AS "Created By",
  "aau"."FIRST_NAME" AS "Requester",
  "aaac"."emailid" AS "Email",
  "wo"."TITLE" AS "Subject",
  "icd"."NAME" AS "Item",
  "rtdef"."NAME" AS "Request Type",
  "pd"."PRIORITYNAME" AS "Priority",
  "std"."STATUSNAME" AS "Request Status",
  "cd"."CATEGORYNAME" AS "Category",
  "scd"."NAME" AS "Subcategory",
  "ti"."FIRST_NAME" AS "Technician",
  a.first_name as "Changed From",
  aa.first_name as "Changed To",
  "qd"."QUEUENAME" AS "Group",
  "wof"."UDF_CHAR3" AS "DC Location",  
  LONGTODATE("wo"."RESPONDEDTIME") AS "Responded Date",
  LONGTODATE("wo"."DUEBYTIME") AS "DueBy Time",
  LONGTODATE("wo"."COMPLETEDTIME") AS "Completed Time",
  "wos"."ISOVERDUE" AS "Overdue Status",
convert(varchar(5),((si.TIMESPENT))/1000/3600)+':'+convert(varchar(5),(((si.TIMESPENT))/1000)%3600/60) "TimeSpent By Techician (HH:MM)",
  convert(varchar(5),(sum(wo.TIMESPENTONREQ))/1000/3600)+':'+convert(varchar(5),((sum(wo.TIMESPENTONREQ))/1000)%3600/60)+':'+convert(varchar(5),
 (((sum(wo.TIMESPENTONREQ)))/1000%60)) "Total Time elapsed",
 adef.org_name "Account",
 sdorganization.name "site",
 wof.UDF_CHAR1 "Platform",
"userdf"."UDF_CHAR1" AS "Customer ID" FROM "WorkOrder" "wo"
 LEFT JOIN "SDUser" "sdu" ON "wo"."REQUESTERID"="sdu"."USERID"
 LEFT JOIN "AaaUser" "aau" ON "sdu"."USERID"="aau"."USER_ID"
 LEFT JOIN "SDUser" "crd" ON "wo"."CREATEDBYID"="crd"."USERID"
 LEFT JOIN "AaaUser" "cri" ON "crd"."USERID"="cri"."USER_ID"
 LEFT JOIN "aaausercontactinfo" "aaauc" on "aaauc"."user_id"="aau"."User_id"
 LEFT JOIN "aaacontactinfo" "aaac" on "aaac"."contactinfo_id"="aaauc"."contactinfo_id"
 LEFT JOIN "WorkOrderStates" "wos" ON "wo"."WORKORDERID"="wos"."WORKORDERID"
 LEFT JOIN "CategoryDefinition" "cd" ON "wos"."CATEGORYID"="cd"."CATEGORYID"
 LEFT JOIN "SubCategoryDefinition" "scd" ON "wos"."SUBCATEGORYID"="scd"."SUBCATEGORYID"
 LEFT JOIN "ItemDefinition" "icd" ON "wos"."ITEMID"="icd"."ITEMID"
 LEFT JOIN "SDUser" "td" ON "wos"."OWNERID"="td"."USERID"
 LEFT JOIN "AaaUser" "ti" ON "td"."USERID"="ti"."USER_ID"
 LEFT JOIN "RequestTypeDefinition" "rtdef" ON "wos"."REQUESTTYPEID"="rtdef"."REQUESTTYPEID"
 LEFT JOIN "PriorityDefinition" "pd" ON "wos"."PRIORITYID"="pd"."PRIORITYID"
 LEFT JOIN "StatusDefinition" "std" ON "wos"."STATUSID"="std"."STATUSID"
 LEFT JOIN "WorkOrder_Queue" "woq" ON "wo"."WORKORDERID"="woq"."WORKORDERID"
 LEFT JOIN "QueueDefinition" "qd" ON "woq"."QUEUEID"="qd"."QUEUEID"
 LEFT JOIN "WorkOrder_Fields" "wof" ON "wo"."WORKORDERID"="wof"."WORKORDERID"
 LEFT JOIN sitedefinition sdef ON sdef.siteid=wo.siteid
 LEFT JOIN accountsitemapping asm ON asm.siteid=sdef.siteid
 LEFT JOIN accountdefinition adef ON adef.org_id=asm.accountid
 Left JOIN sdorganization on sdorganization.org_id=Sdef.siteid
 LEFT JOIN WO_Assessment woas ON wo.WORKORDERID = woas.WORKORDERID
 LEFT JOIN WO_Tech_Info si ON woas.ASSESSMENTID = si.ASSESSMENTID
 LEFT JOIN AAAUser a ON si.TECHNICIANID = a.USER_ID
 LEFT JOIN AAAUser aa ON si.NEXTTECHNICIANID = aa.USER_ID
LEFT JOIN useradditionalfields userdf ON userdf.instance_id = "sdu"."USERID"
 where (wo.CREATEDTIME) >= <from_thismonth> AND (wo.CREATEDTIME) <= <to_thismonth> and TECHNICIANID is not NULL
 Group by wo.WORKORDERID, wo.CREATEDTIME, wo.RESOLVEDTIME, aau.FIRST_NAME, cri.First_name,
 wo.Title, icd.name, rtdef.name, pd.PRIORITYNAME, std.statusname, cd.categoryname, scd.name,
  ti.first_name, qd.queuename, wo.respondedtime, wo.duebytime, wo.completedtime,
  wos.isoverdue, aaac.Emailid,wof.udf_char3,wof.UDF_CHAR1,adef.org_name, sdorganization.name,a.FIRST_NAME,aa.FIRST_NAME,si.NEXTTECHNICIANID,woas.EXECUTEDTIME,si.TIMESPENT,userdf.UDF_CHAR1

                New to ADSelfService Plus?