See this link for an example I just posted.
https://www.lansweeper.com/forum/yaf_postst16374_Helpdesk-report-no-results.aspx#post55084
The key takeaways are (in reverse order):
The code in the From portion of the query looks like this for each "element" of the ticket.
Inner Join (Select Top 1000000 htblticketcustomfield.ticketid,
htblticketcustomfield.data
From htblticketcustomfield
Inner Join htblcustomfields On htblcustomfields.fieldid =
htblticketcustomfield.fieldid
Where htblcustomfields.name Like 'PCD-HDD ToteID Name') As ToteIDName
On htblticket.ticketid = ToteIDName.ticketid
This value needs to match the Ticket Field
Where htblcustomfields.name Like 'PCD-HDD ToteID Name'
This has to be unique value
As ToteIDName
This has to match the value listed in the As field
ToteIDName.ticketid
The data from the Select portion of the SQL query should look like this:
ToteIDName.data As ToteIDName