Tested in Build PGSQL (14300) or MSSQL (14306)
PGSQL & MSSQL:
SELECT wo.WORKORDERID "Request ID",
aau.FIRST_NAME "Requester",
dpt.DEPTNAME "Department",
std.STATUSNAME "Request Status",
wo.TITLE "Subject",
rtdef.NAME "Request Type",
sdo.NAME "Site",
LONGTODATE(wo.CREATEDTIME) CREATEDTIME,
aau1.FIRST_NAME PERFORMEDBY,
LONGTODATE(woh.OPERATIONTIME) OPERATIONTIME,
qd1.queuename "Changed From",
qd2.queuename "Changed To"
from WorkOrder wo
LEFT JOIN SDUser sdu ON wo.REQUESTERID=sdu.USERID
LEFT JOIN AaaUser aau ON sdu.USERID=aau.USER_ID
LEFT JOIN DepartmentDefinition dpt ON wo.DEPTID=dpt.DEPTID
LEFT JOIN WorkOrderStates wos ON wo.WORKORDERID=wos.WORKORDERID
LEFT JOIN StatusDefinition std ON wos.STATUSID=std.STATUSID
LEFT JOIN WorkOrderHistory woh ON wo.WORKORDERID = woh.WORKORDERID
LEFT JOIN WorkOrderHistoryDiff wohd ON woh.HISTORYID = wohd.HISTORYID
LEFT JOIN AaaUser aau1 ON aau1.USER_ID = woh.OPERATIONOWNERID
LEFT JOIN SiteDefinition siteDef ON wo.SITEID=siteDef.SITEID
LEFT JOIN SDOrganization sdo ON siteDef.SITEID=sdo.ORG_ID
LEFT JOIN RequestTypeDefinition rtdef ON wos.REQUESTTYPEID=rtdef.REQUESTTYPEID
left join QueueDefinition qd1 on cast(cast(wohd.prev_value as varchar) as int) =qd1.QUEUEID
left join QueueDefinition qd2 on cast(cast(wohd.current_value as varchar) as int) =qd2.QUEUEID
where wohd.COLUMNNAME in ('QUEUEID') order by 1,woh.OPERATIONTIME desc