Guest User

Untitled

a guest
May 25th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. SELECT Customer.customerId,
  2. Customer.customerNr,
  3. Customer.spcsDealNr,
  4. Customer.customerName,
  5. CustomerContact.name,
  6. CustomerContact.phone1,
  7. Customer.objectCity,
  8. MAX(TheLastDate.regdate) AS regdate,
  9. (SELECT MAX(regdate) FROM jgl_order WHERE jgl_order.alarmsystemid = CustomerFilesFields.value_int GROUP BY jgl_order.alarmsystemid) AS TheLastDateYes
  10. FROM jgl_customerFiles AS CustomerFiles
  11. INNER JOIN jgl_customer AS Customer ON CustomerFiles.customerId = Customer.customerId
  12. LEFT OUTER JOIN jgl_customerContact AS CustomerContact ON CustomerContact.customerId = Customer.customerId AND CustomerContact.defaultCustomerContact = 1
  13. INNER JOIN jgl_customerFilesFields AS CustomerFilesFields ON CustomerFiles.customerFileId = CustomerFilesFields.customerFileId AND CustomerFilesFields.field = 'dealAlarmSystemId'
  14. INNER JOIN jgl_customerFilesFields AS OptionFields ON CustomerFiles.customerFileId = OptionFields.customerFileId AND OptionFields.field = 'dealalarm_options'
  15. LEFT OUTER JOIN jgl_order AS TheLastDate ON TheLastDate.alarmsystemid = CustomerFilesFields.value_int AND TheLastDate.revisionDone = 1
  16. LEFT OUTER JOIN jgl_customerRevision As CustomerRevision ON CustomerRevision.customerId = Customer.customerId AND CustomerRevision.status = 'inactive'
  17. WHERE
  18. CustomerFiles.softType = 'dealalarm'
  19. AND (CONCAT(Customer.customerNr, ':',Customer.spcsDealNr) LIKE '%%')
  20. AND Customer.customerName LIKE '%%'
  21. AND Customer.objectCity LIKE '%%'
  22. AND Customer.customerName NOT LIKE '%XXX%'
  23. AND ((
  24. TheLastDate.regdate < (NOW() - INTERVAL 1 YEAR)
  25. AND (OptionFields.value LIKE '2;%' OR OptionFields.value LIKE ';2;%')
  26. )
  27. OR (
  28. TheLastDate.regdate < (NOW() - INTERVAL 3 YEAR)
  29. AND (OptionFields.value LIKE '11;%' OR OptionFields.value LIKE ';11;%')
  30. )
  31. OR TheLastDate.regdate IS NULL
  32. )
  33. AND ((OptionFields.value LIKE '11;%' OR OptionFields.value LIKE ';11;%') OR (OptionFields.value LIKE '2;%' OR OptionFields.value LIKE ';2;%'))
  34. AND CustomerRevision.customerRevisionId IS NULL ORDER BY TheLastDate.regdate
  35. GROUP BY CustomerFilesFields.value_int
Add Comment
Please, Sign In to add comment