Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DECLARE
- @siteKey NVARCHAR(50)= 'P32'
- ,@effectiveDateTime DATETIME = '08/22/2019'
- ,@operationKey NVARCHAR(250) = '015'
- ,@equipmentLocationKey NVARCHAR(MAX) = '-1'
- ,@assigment BIT = 0
- ,@equipmentKey NVARCHAR(50) = '-1'
- ,@moldLetter NVARCHAR(50) = 'A'
- SET NOCOUNT ON;
- IF @assigment = 0
- BEGIN
- SELECT distinct equi.equipment_key,
- equi.equipment,
- equi.eqty_equipment_type_key,
- eqty.equipment_type,
- equi.eqlo_equipment_location_key,
- eqlo.equipment_location
- --scoe.opeq_operation_key AS operation_key
- FROM schemas_operations_equipments scoe,
- equipments equi,
- equipment_types eqty,
- equipment_locations eqlo,
- operations_equipments opeq
- WHERE (scoe.opeq_operation_key IN (SELECT * FROM SPLIT(@operationKey)) OR @operationKey = '-1')
- AND scoe.opeq_site_key = @siteKey
- AND @effectiveDateTime >= scoe.start_date
- AND (@effectiveDateTime <= isnull(ISNULL(scoe.end_date,scoe.date1),@effectiveDateTime) /*OR @assigment = 1*/)
- AND scoe.opeq_equi_equipment_key = equi.equipment_key
- AND scoe.opeq_equi_site_key = equi.site_site_key
- AND equi.eqty_equipment_type_key = eqty.equipment_type_key
- AND equi.eqty_site_key = eqty.site_site_key
- AND equi.eqlo_equipment_location_key = eqlo.equipment_location_key
- AND equi.eqlo_site_key = eqlo.site_site_key
- AND opeq.oper_operation_key = scoe.opeq_operation_key
- AND opeq.oper_site_key = scoe.opeq_site_key
- AND opeq.equi_equipment_key = scoe.opeq_equi_equipment_key
- AND opeq.equi_site_key = scoe.opeq_equi_site_key
- AND opeq.status = 'ACT'
- AND scoe.record_status = 'ACT'
- AND equi.status='ACT'
- --AND (equi.eqlo_equipment_location_key = @equipmentLocationKey OR @equipmentLocationKey = '-1')
- AND (equi.eqlo_equipment_location_key IN (SELECT * FROM SPLIT(@equipmentLocationKey)) OR @equipmentLocationKey = '-1')
- AND equi.equipment_key <> 'MRB01'
- AND (equi.equipment_key = @equipmentKey OR @equipmentKey = '-1')
- AND scoe.string3=@moldLetter
- ORDER BY eqlo.equipment_location,
- equi.equipment_key
- END
- ELSE
- BEGIN
- SELECT DISTINCT equi.equipment_key,
- equi.equipment,
- equi.eqlo_equipment_location_key,
- eqlo.equipment_location
- --opeq.oper_operation_key AS operation_key
- FROM operations_equipments opeq,
- equipments equi,
- equipment_locations eqlo
- WHERE (opeq.oper_operation_key IN (SELECT * FROM SPLIT(@operationKey)) OR @operationKey = '-1')
- AND opeq.oper_site_key = @siteKey
- AND opeq.equi_equipment_key = equi.equipment_key
- AND opeq.equi_site_key = equi.site_site_key
- AND equi.eqlo_equipment_location_key = eqlo.equipment_location_key
- AND equi.eqlo_site_key = eqlo.site_site_key
- AND equi.equipment_key <> 'MRB01'
- AND (equi.equipment_key = @equipmentKey OR @equipmentKey = '-1')
- AND equi.status='ACT'
- AND opeq.status = 'ACT'
- END
- SET NOCOUNT OFF;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement