Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.90 KB | None | 0 0
  1. SELECT
  2. tid,
  3. productSerialNumber,
  4. labelSerialNumber,
  5. NVL(formatId, 'N/A') formatId,
  6. NVL(formatIdDesc, 'N/A') formatIdDesc,
  7. NVL(labelPartNumber, 'N/A') labelPartNumber,
  8. stageDesc,
  9. to_char(timestamp, 'yyyy-mm-dd hh24:mi:ss') timestamp,
  10. userId,
  11. cnt
  12. FROM (SELECT ProductData.*,
  13. row_number() over(ORDER BY
  14. CASE
  15. WHEN :orderDirection like '%asc%' THEN
  16. CASE
  17. WHEN :orderBy='productSerialNumber' THEN productSerialNumber
  18. WHEN :orderBy='labelSerialNumber' THEN labelSerialNumber
  19. WHEN :orderBy='formatId' THEN formatId
  20. WHEN :orderBy='formatIdDesc' THEN formatIdDesc
  21. WHEN :orderBy='labelPartNumber' THEN labelPartNumber
  22. WHEN :orderBy='prodDesc' THEN prodDesc
  23. WHEN :orderBy='timestamp' THEN to_char(timestamp, 'yyyy-mm-dd hh24:mi:ss')
  24. WHEN :orderBy='userId' THEN userId
  25. ELSE to_char(timestamp, 'yyyy-mm-dd hh24:mi:ss')
  26. END
  27.  
  28. END ASC,
  29. CASE
  30. WHEN :orderDirection like '%desc%' THEN
  31. CASE
  32. WHEN :orderBy='productSerialNumber' THEN productSerialNumber
  33. WHEN :orderBy='labelSerialNumber' THEN labelSerialNumber
  34. WHEN :orderBy='formatId' THEN formatId
  35. WHEN :orderBy='formatIdDesc' THEN formatIdDesc
  36. WHEN :orderBy='labelPartNumber' THEN labelPartNumber
  37. WHEN :orderBy='stageDesc' THEN stageDesc
  38. WHEN :orderBy='timestamp' THEN to_char(timestamp, 'yyyy-mm-dd hh24:mi:ss')
  39. WHEN :orderBy='userId' THEN userId
  40. ELSE to_char(timestamp, 'yyyy-mm-dd hh24:mi:ss')
  41. END
  42.  
  43. END DESC
  44. , tid ASC) line_number
  45. FROM (select ProductData_inner.*, COUNT(1) OVER() cnt
  46. from (select pd_tran.tid,
  47. pd_res.engine_serial_number productSerialNumber,
  48. pd_res.machine_serial_number labelSerialNumber,
  49. lf.format_id formatId,
  50. lf.format_id_desc formatIdDesc,
  51. NULLIF(pd_tran.format, 'DSEL Labels') labelPartNumber,
  52. stagelu.stage_desc stageDesc,
  53. pd_res.created_timestamp timestamp,
  54. pd_res.cws_id userId
  55. from pd_RESULTS pd_res
  56. left outer join pd_TRANSACTION pd_tran on pd_tran.results_id = pd_res.result_id
  57. left outer join pd_TRANSACTION_FIELDS pd_tran_flds on pd_tran.tid =
  58. pd_tran_flds.tid
  59. and (pd_tran_flds.field_name =
  60. '-CERT_AR-' or
  61. pd_tran_flds.field_name =
  62. 'cert_arrangement')
  63. left outer join LABEL_FORMAT lf on lf.label_part_num = pd_tran.format
  64. inner join stage_lu stagelu on stagelu.stage_id=pd_res.stage_id
  65. where (:productSerialNumber is null or
  66. pd_res.engine_serial_number =
  67. :productSerialNumber)
  68. and (:labelSerialNumber is null or
  69. pd_res.machine_serial_number = :labelSerialNumber)
  70. and ('nullValue' = :formatDescFlag or
  71. TRIM(lf.format_id_desc) in (:formatDesc))
  72. and (:formatId is null or
  73. lf.format_id = :formatId)
  74. and (:fromDate is null or
  75. pd_res.created_timestamp >=
  76. to_date(:fromDate, 'mm/dd/yyyy'))
  77. and (:todate is null or
  78. pd_res.created_timestamp <
  79. (to_date(:todate, 'mm/dd/yyyy') + 1))) ProductData_inner) ProductData)
  80. WHERE line_number > :iDisplayStart
  81. AND line_number <=
  82. (
  83. CASE
  84. WHEN ((:exportToExcelrequest is not null) and cnt>50000) THEN 50000
  85. WHEN ((:exportToExcelrequest is not null) and cnt<=50000) THEN cnt
  86. ELSE :iDisplayEnd
  87. END
  88. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement