We did some modifications to the query by making use of sub-queries so that each custom field gets their own column.
Select Distinct Top 1000000 htblticket.ticketid,
htblticket.subject,
htblticket.date,
CustomField1.name As Name1,
CustomField1.data As Data1,
CustomField2.name As Name2,
CustomField2.data As Data2,
CustomField3.name As Name3,
CustomField3.data As Data3
From htblticket
Inner Join (Select Top 1000000 htblticketcustomfield.ticketid,
htblcustomfields.name,
htblticketcustomfield.data
From htblticketcustomfield
Inner Join htblcustomfields On htblcustomfields.fieldid =
htblticketcustomfield.fieldid
Where htblticketcustomfield.fieldid = 54) As CustomField1
On htblticket.ticketid = CustomField1.ticketid
Inner Join htblnotes On htblticket.ticketid = htblnotes.ticketid
Inner Join (Select Top 1000000 htblticketcustomfield.ticketid,
htblcustomfields.name,
htblticketcustomfield.fieldid,
htblticketcustomfield.data
From htblticketcustomfield
Inner Join htblcustomfields On htblcustomfields.fieldid =
htblticketcustomfield.fieldid
Where htblticketcustomfield.fieldid = 58) As CustomField2
On htblticket.ticketid = CustomField2.ticketid
Inner Join (Select Top 1000000 htblticketcustomfield.ticketid,
htblcustomfields.name,
htblticketcustomfield.fieldid,
htblticketcustomfield.data
From htblticketcustomfield
Inner Join htblcustomfields On htblcustomfields.fieldid =
htblticketcustomfield.fieldid
Where htblticketcustomfield.fieldid = 42) As CustomField3
On htblticket.ticketid = CustomField3.ticketid
Order By htblticket.ticketid