Hey guys,
I have a couple of Reports in Use that Document the Time worked for a Custom Field "Category" that's just a Basic Combobox to categorize/label the Tickets for example as "VPN, Office365, Lansweeper, User, Client, Hardware etc."
With this I already have reports that count the Time correctly per Week, month and year but all of them share the common issue that the Order By Function doesn't really seem to work. When I try to order it by the "TimeWorked" it won't work because the Reports are using the "SELECT DISTINCT" Function and not just a regular SELECT.
I had found out a way to order them by just regular time but then it seems to just order by the first Number and then by the Second for the "Days" for example - "9 days 5 hours 30 minutes" is above the "32 days 15 hours 45 minutes" one because it doesn't seem to Order By Minutes worked, instead it orders by days (?)
Here is my current Report, would appreciate any help! 🙂
Select Distinct Top 1000000 htblticketcustomfield.data As Category,
Convert(nvarchar(10),Ceiling(Floor(Convert(integer,Custom1.MinutesWorked) /
60 / 24))) + ' days ' +
Convert(nvarchar(10),Ceiling(Floor(Convert(integer,Custom1.MinutesWorked) /
60 % 24))) + ' hours ' +
Convert(nvarchar(10),Ceiling(Floor(Convert(integer,Custom1.MinutesWorked) %
60))) + ' minutes' As TimeWorked
From htblticketcustomfield
Inner Join htblcustomfields On htblticketcustomfield.fieldid =
htblcustomfields.fieldid
Inner Join (Select Top 1000000 htblticketcustomfield.data,
Sum(htblnotes.timeworked) As MinutesWorked
From htblticketcustomfield
Inner Join htblcustomfields On htblcustomfields.fieldid =
htblticketcustomfield.fieldid
Inner Join htblnotes On
htblnotes.ticketid = htblticketcustomfield.ticketid
Inner Join htblhistory On htblticketcustomfield.ticketid =
htblhistory.ticketid
Inner Join htblticketstates On htblticketstates.ticketstateid =
htblhistory.ticketstateid
Inner Join htblticket On
htblticket.ticketid = htblticketcustomfield.ticketid
Inner Join htblhistorytypes On htblhistorytypes.typeid =
htblhistory.typeid
Where htblticketstates.statename = 'Closed' And htblticketstates.statename =
'Closed' And htblticket.spam <> 'True' And htblhistorytypes.name
In ('Status changed', 'Note added and state changed',
'Internal note added and state changed') And
htblcustomfields.name Like '%Category%' And DatePart(isoww,
htblnotes.date) = DatePart(isoww, GetDate()) And DatePart(yyyy,
htblnotes.date) = DatePart(yyyy, GetDate()) And
htblnotes.timeworked Is Not Null
Group By htblticketcustomfield.data
Having Max(htblhistory.date) > GetDate() - 365) As Custom1 On
Custom1.data = htblticketcustomfield.data
Order by TimeWorked Desc