Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. DECLARE
  2. @siteKey NVARCHAR(50)= 'P32'
  3. ,@effectiveDateTime DATETIME = '08/22/2019'
  4. ,@operationKey NVARCHAR(250) = '015'
  5. ,@equipmentLocationKey NVARCHAR(MAX) = '-1'
  6. ,@assigment BIT = 0
  7. ,@equipmentKey NVARCHAR(50) = '-1'
  8. ,@moldLetter NVARCHAR(50) = 'A'
  9.  
  10. SET NOCOUNT ON;
  11.  
  12. IF @assigment = 0
  13. BEGIN
  14. SELECT distinct equi.equipment_key,
  15. equi.equipment,
  16. equi.eqty_equipment_type_key,
  17. eqty.equipment_type,
  18. equi.eqlo_equipment_location_key,
  19. eqlo.equipment_location
  20. --scoe.opeq_operation_key AS operation_key
  21. FROM schemas_operations_equipments scoe,
  22. equipments equi,
  23. equipment_types eqty,
  24. equipment_locations eqlo,
  25. operations_equipments opeq
  26. WHERE (scoe.opeq_operation_key IN (SELECT * FROM SPLIT(@operationKey)) OR @operationKey = '-1')
  27. AND scoe.opeq_site_key = @siteKey
  28. AND @effectiveDateTime >= scoe.start_date
  29. AND (@effectiveDateTime <= isnull(ISNULL(scoe.end_date,scoe.date1),@effectiveDateTime) /*OR @assigment = 1*/)
  30. AND scoe.opeq_equi_equipment_key = equi.equipment_key
  31. AND scoe.opeq_equi_site_key = equi.site_site_key
  32. AND equi.eqty_equipment_type_key = eqty.equipment_type_key
  33. AND equi.eqty_site_key = eqty.site_site_key
  34. AND equi.eqlo_equipment_location_key = eqlo.equipment_location_key
  35. AND equi.eqlo_site_key = eqlo.site_site_key
  36. AND opeq.oper_operation_key = scoe.opeq_operation_key
  37. AND opeq.oper_site_key = scoe.opeq_site_key
  38. AND opeq.equi_equipment_key = scoe.opeq_equi_equipment_key
  39. AND opeq.equi_site_key = scoe.opeq_equi_site_key
  40. AND opeq.status = 'ACT'
  41. AND scoe.record_status = 'ACT'
  42. AND equi.status='ACT'
  43. --AND (equi.eqlo_equipment_location_key = @equipmentLocationKey OR @equipmentLocationKey = '-1')
  44. AND (equi.eqlo_equipment_location_key IN (SELECT * FROM SPLIT(@equipmentLocationKey)) OR @equipmentLocationKey = '-1')
  45. AND equi.equipment_key <> 'MRB01'
  46. AND (equi.equipment_key = @equipmentKey OR @equipmentKey = '-1')
  47. AND scoe.string3=@moldLetter
  48. ORDER BY eqlo.equipment_location,
  49. equi.equipment_key
  50. END
  51. ELSE
  52. BEGIN
  53. SELECT DISTINCT equi.equipment_key,
  54. equi.equipment,
  55. equi.eqlo_equipment_location_key,
  56. eqlo.equipment_location
  57. --opeq.oper_operation_key AS operation_key
  58. FROM operations_equipments opeq,
  59. equipments equi,
  60. equipment_locations eqlo
  61. WHERE (opeq.oper_operation_key IN (SELECT * FROM SPLIT(@operationKey)) OR @operationKey = '-1')
  62. AND opeq.oper_site_key = @siteKey
  63. AND opeq.equi_equipment_key = equi.equipment_key
  64. AND opeq.equi_site_key = equi.site_site_key
  65. AND equi.eqlo_equipment_location_key = eqlo.equipment_location_key
  66. AND equi.eqlo_site_key = eqlo.site_site_key
  67. AND equi.equipment_key <> 'MRB01'
  68. AND (equi.equipment_key = @equipmentKey OR @equipmentKey = '-1')
  69. AND equi.status='ACT'
  70. AND opeq.status = 'ACT'
  71. END
  72.  
  73. SET NOCOUNT OFF;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement