‎01-16-2017 08:20 PM
Select Top 1000000 htblusers1.name As [Ticket User],
htblticket.ticketid As [Ticket #],
htblusers.name As [Ticket Creator],
htblticket.date As [Creation Date],
htblticketcustomfield.data As [Employee Name],
htblticketcustomfield1.data As [Entry date],
htblticketcustomfield2.data As [Est-ce un remplacement]
From htblhistorytypes
Inner Join htblhistory On htblhistorytypes.typeid = htblhistory.typeid
Inner Join htblticket On htblticket.ticketid = htblhistory.ticketid
Inner Join htblusers On htblusers.userid = htblhistory.userid
Inner Join htblusers htblusers1 On htblticket.fromuserid = htblusers1.userid
And htblhistory.userid != htblusers1.userid
Inner Join htblticketcustomfield On htblticket.ticketid =
htblticketcustomfield.ticketid
Inner Join htblcustomfields On htblcustomfields.fieldid =
htblticketcustomfield.fieldid
Inner Join htblticketcustomfield htblticketcustomfield1
On htblticket.ticketid = htblticketcustomfield1.ticketid
Inner Join htblcustomfields htblcustomfields1 On htblcustomfields1.fieldid =
htblticketcustomfield1.fieldid
Inner Join htblticketcustomfield htblticketcustomfield2
On htblticket.ticketid = htblticketcustomfield2.ticketid
Inner Join htblcustomfields htblcustomfields2 On htblcustomfields2.fieldid =
htblticketcustomfield2.fieldid
Where htblcustomfields.name = 'First name, Last name' And
htblcustomfields1.name = 'Date d''entrée en vigueur' And
htblcustomfields2.name = 'Est-ce un remplacement?' And
htblhistorytypes.typeid = 31
Order By [Entry date] Desc,
[Est-ce un remplacement]
Solved! Go to Solution.
‎01-23-2017 02:28 PM
Select Top 1000000 htblusers.name As [Ticket User],
htblticket.ticketid As [Ticket #],
htblusers1.name As [Ticket agent],
htblticket.date As [Creation Date],
htblticketcustomfield.data As [Employee Name],
htblticketcustomfield1.data As [Entry date],
htblticketcustomfield2.data As [Est-ce un remplacement],
DateDiff(DAY, htblticket.date, Cast(htblticketcustomfield1.data As datetime))
As [Délai d'avis]
From htblticket
Left Join htblusers On htblusers.userid = htblticket.fromuserid
Inner Join htblagents On htblagents.agentid = htblticket.agentid
Left Join htblusers htblusers1 On htblagents.userid = htblusers1.userid
Left Join htblticketcustomfield On htblticket.ticketid =
htblticketcustomfield.ticketid
Inner Join htblcustomfields On htblcustomfields.fieldid =
htblticketcustomfield.fieldid And htblcustomfields.name =
'First name, Last name'
Left Join htblticketcustomfield htblticketcustomfield1
On htblticket.ticketid = htblticketcustomfield1.ticketid
Inner Join htblcustomfields htblcustomfields1 On htblcustomfields1.fieldid =
htblticketcustomfield1.fieldid And htblcustomfields1.name =
'Date d''entrée en vigueur'
Left Join htblticketcustomfield htblticketcustomfield2
On htblticket.ticketid = htblticketcustomfield2.ticketid
Inner Join htblcustomfields htblcustomfields2 On htblcustomfields2.fieldid =
htblticketcustomfield2.fieldid And htblcustomfields2.name =
'Est-ce un remplacement?'
Left Join htblticketcustomfield htblticketcustomfield3
On htblticket.ticketid = htblticketcustomfield3.ticketid
Inner Join htblcustomfields htblcustomfields3 On htblcustomfields3.fieldid =
htblticketcustomfield3.fieldid And htblcustomfields3.name =
'Est-ce une demande de changement?'
Left Join htbltickettypes On htblticket.tickettypeid =
htbltickettypes.tickettypeid
Where htblticketcustomfield3.data = 'Non' And DatePart(month, DateAdd(month, -1,
DatePart(month, GetDate()))) >= DatePart(month,
Cast(htblticketcustomfield1.data As datetime)) And DatePart(month,
DateAdd(month, -1, DatePart(month, GetDate()))) <= DatePart(month,
Cast(htblticketcustomfield1.data As datetime)) And
htbltickettypes.tickettypeid = 7
Order By [Entry date],
[Est-ce un remplacement]
‎01-23-2017 02:28 PM
Select Top 1000000 htblusers.name As [Ticket User],
htblticket.ticketid As [Ticket #],
htblusers1.name As [Ticket agent],
htblticket.date As [Creation Date],
htblticketcustomfield.data As [Employee Name],
htblticketcustomfield1.data As [Entry date],
htblticketcustomfield2.data As [Est-ce un remplacement],
DateDiff(DAY, htblticket.date, Cast(htblticketcustomfield1.data As datetime))
As [Délai d'avis]
From htblticket
Left Join htblusers On htblusers.userid = htblticket.fromuserid
Inner Join htblagents On htblagents.agentid = htblticket.agentid
Left Join htblusers htblusers1 On htblagents.userid = htblusers1.userid
Left Join htblticketcustomfield On htblticket.ticketid =
htblticketcustomfield.ticketid
Inner Join htblcustomfields On htblcustomfields.fieldid =
htblticketcustomfield.fieldid And htblcustomfields.name =
'First name, Last name'
Left Join htblticketcustomfield htblticketcustomfield1
On htblticket.ticketid = htblticketcustomfield1.ticketid
Inner Join htblcustomfields htblcustomfields1 On htblcustomfields1.fieldid =
htblticketcustomfield1.fieldid And htblcustomfields1.name =
'Date d''entrée en vigueur'
Left Join htblticketcustomfield htblticketcustomfield2
On htblticket.ticketid = htblticketcustomfield2.ticketid
Inner Join htblcustomfields htblcustomfields2 On htblcustomfields2.fieldid =
htblticketcustomfield2.fieldid And htblcustomfields2.name =
'Est-ce un remplacement?'
Left Join htblticketcustomfield htblticketcustomfield3
On htblticket.ticketid = htblticketcustomfield3.ticketid
Inner Join htblcustomfields htblcustomfields3 On htblcustomfields3.fieldid =
htblticketcustomfield3.fieldid And htblcustomfields3.name =
'Est-ce une demande de changement?'
Left Join htbltickettypes On htblticket.tickettypeid =
htbltickettypes.tickettypeid
Where htblticketcustomfield3.data = 'Non' And DatePart(month, DateAdd(month, -1,
DatePart(month, GetDate()))) >= DatePart(month,
Cast(htblticketcustomfield1.data As datetime)) And DatePart(month,
DateAdd(month, -1, DatePart(month, GetDate()))) <= DatePart(month,
Cast(htblticketcustomfield1.data As datetime)) And
htbltickettypes.tickettypeid = 7
Order By [Entry date],
[Est-ce un remplacement]
‎01-17-2017 03:02 PM
‎01-17-2017 09:25 AM
Select Top 1000000 htblusers1.name As [Ticket User],
htblticket.ticketid As [Ticket #],
htblusers.name As [Ticket Creator],
htblticket.date As [Creation Date],
htblticketcustomfield.data As [Employee Name],
htblticketcustomfield1.data As [Entry date],
htblticketcustomfield2.data As [Est-ce un remplacement]
From htblhistorytypes
Inner Join htblhistory On htblhistorytypes.typeid = htblhistory.typeid
Inner Join htblticket On htblticket.ticketid = htblhistory.ticketid
Inner Join htblusers On htblusers.userid = htblhistory.userid
Inner Join htblusers htblusers1 On htblticket.fromuserid = htblusers1.userid
And htblhistory.userid != htblusers1.userid
Inner Join htblticketcustomfield On htblticket.ticketid =
htblticketcustomfield.ticketid
Inner Join htblcustomfields On htblcustomfields.fieldid =
htblticketcustomfield.fieldid
Inner Join htblticketcustomfield htblticketcustomfield1
On htblticket.ticketid = htblticketcustomfield1.ticketid
Inner Join htblcustomfields htblcustomfields1 On htblcustomfields1.fieldid =
htblticketcustomfield1.fieldid
Inner Join htblticketcustomfield htblticketcustomfield2
On htblticket.ticketid = htblticketcustomfield2.ticketid
Inner Join htblcustomfields htblcustomfields2 On htblcustomfields2.fieldid =
htblticketcustomfield2.fieldid
Where htblcustomfields.name = 'First name, Last name' And
htblcustomfields1.name = 'Date d''entrée en vigueur' Or
htblcustomfields2.name = 'Est-ce un remplacement?' And
htblhistorytypes.typeid = 31 Or
htblticket.date BETWEEN getdate() AND Dateadd(Day, -30, GETDATE())
Order By [Entry date] Desc,
[Est-ce un remplacement]
Experience Lansweeper with your own data. Sign up now for a 14-day free trial.
Try Now