Select Top 1000000 htblticket.ticketid,
'#' + Cast(htblticket.ticketid As nvarchar) As Ticket,
htblusers1.name As AssignedAgent,
htblticket.date As CreationDate,
htblticket.updated As LastUpdated,
'../helpdesk/icons/' + htbltickettypes.icon As icon
From htblticket
Inner Join htblpriorities On htblpriorities.priority = htblticket.priority
Inner Join htblticketstates On htblticketstates.ticketstateid =
htblticket.ticketstateid
Inner Join htblusers On htblusers.userid = htblticket.fromuserid
Left Join htblagents On htblagents.agentid = htblticket.agentid
Left Join htblusers htblusers1 On htblusers1.userid = htblagents.userid
Inner Join htbltickettypes On htblticket.tickettypeid =
htbltickettypes.tickettypeid
Inner Join htblsource On htblticket.sourceid = htblsource.sourceid
Inner Join htblusers htblusers2 On htblticket.userid_lastnote =
htblusers2.userid
Where (htblticket.updated < GetDate() - 3 And htbltickettypes.typename <>
'Employee Seperation') Or
(htbltickettypes.typename <> 'project')
Order By htblticket.ticketid