DBA Data[Home] [Help]

APPS.WSH_DELIVERY_LEGS_ACTIONS SQL Statements

The following lines contain the word 'select', 'insert', 'update' or 'delete':

Line: 10

select delivery_leg_id
from wsh_delivery_legs l, wsh_trip_stops s
where s.trip_id = p_trip_id
and   l.delivery_id = p_delivery_id
and   s.stop_id = l.pick_up_stop_id
and   s.stop_location_id = p_pickup_loc_id;
Line: 45

SELECT   status_code ,
         NVL(SHIPMENTS_TYPE_FLAG,'O') SHIPMENTS_TYPE_FLAG,   -- J-IB-NPARIKH
         stop_location_id
FROM   wsh_trip_stops
WHERE stop_id = l_trip_stop_id;
Line: 52

SELECT  initial_pickup_location_id,
initial_pickup_date,
ultimate_dropoff_location_id,
ultimate_dropoff_date,
organization_id,
status_code,
nvl(shipment_direction,'O') shipment_direction,    -- J-IB-NPARIKH
-- J: W/V Changes
gross_weight,
net_weight,
volume,
mode_of_transport,
freight_terms_code,
name,
customer_id
FROM    wsh_new_deliveries
WHERE delivery_id = del_id;
Line: 72

select status_code, planned_flag,
       NVL(SHIPMENTS_TYPE_FLAG,'O') SHIPMENTS_TYPE_FLAG,   -- J-IB-NPARIKH
       mode_of_transport
from wsh_trips
where trip_id = c_trip_id
FOR UPDATE NOWAIT;
Line: 82

SELECT   dg.delivery_leg_id,
st1.stop_location_id,
st2.stop_location_id
FROM    wsh_trip_stops st1,
wsh_trip_stops st2,
wsh_delivery_legs dg
WHERE st1.stop_id = dg.pick_up_stop_id AND
st2.stop_id = dg.drop_off_stop_id AND
st1.trip_id = p_trip_id AND
st2.trip_id = p_trip_id AND
dg.delivery_id = del_id
FOR UPDATE NOWAIT;
Line: 112

SELECT   stop_id, stop_sequence_number,
         NVL(SHIPMENTS_TYPE_FLAG,'O') SHIPMENTS_TYPE_FLAG   -- J-IB-NPARIKH
FROM    wsh_trip_stops
WHERE stop_location_id = l_location_id AND
trip_id = p_trip_id AND
status_code <> 'CL'
AND PLANNED_ARRIVAL_DATE = NVL(l_PLANNED_ARRIVAL_DATE,PLANNED_ARRIVAL_DATE)
AND PLANNED_DEPARTURE_DATE = NVL(l_PLANNED_DEPARTURE_DATE,PLANNED_DEPARTURE_DATE)
FOR UPDATE NOWAIT;
Line: 124

SELECT   stop_id, stop_sequence_number,
         NVL(SHIPMENTS_TYPE_FLAG,'O') SHIPMENTS_TYPE_FLAG   -- J-IB-NPARIKH
FROM    wsh_trip_stops
WHERE stop_location_id = l_location_id AND
trip_id = p_trip_id AND
stop_sequence_number = nvl(l_stop_sequence,stop_sequence_number) AND
status_code <> 'CL'
FOR UPDATE NOWAIT;
Line: 134

SELECT   max(dg.sequence_number)
FROM    wsh_delivery_legs dg
WHERE dg.delivery_id = del_id;
Line: 139

SELECT stop_sequence_number
FROM wsh_trip_stops
WHERE stop_id = l_stop_id;
Line: 144

SELECT 'Y'
FROM wsh_trip_stops wts1, wsh_trip_stops wts2
WHERE wts1.trip_id=p_trip_id
AND wts2.trip_id=p_trip_id
AND wts1.stop_id<>wts2.stop_id
AND wts1.stop_id=p_stop_id
AND ((wts2.physical_location_id=wts1.stop_location_id AND wts2.physical_stop_id IS NULL)
     OR (wts1.physical_location_id=wts2.stop_location_id AND  wts1.physical_stop_id IS NULL)
    );
Line: 157

  select id,rownum*10
  from(
    select id
    from   wsh_tmp
    order  by to_date(column1,'DD-MM-RRRR HH24:MI:SS'),flag desc
  );
Line: 166

select wsh_wv_utils.convert_uom( WEIGHT_UOM_CODE, p_wt_uom, DEPARTURE_GROSS_WEIGHT, null) gross_weight,
       wsh_wv_utils.convert_uom( WEIGHT_UOM_CODE, p_wt_uom, DEPARTURE_NET_WEIGHT, null) net_weight,
       wsh_wv_utils.convert_uom( VOLUME_UOM_CODE, p_vol_uom, DEPARTURE_VOLUME, null) volume
from   wsh_trip_stops
where  trip_id = p_trip_id
and    stop_sequence_number < p_stop_seq
order  by stop_sequence_number desc;
Line: 175

select 'x'
from   wsh_trip_stops
where  trip_id = p_trip_id
and    stop_sequence_number > p_stop_seq;
Line: 538

       DELETE FROM WSH_TMP;
Line: 542

           INSERT INTO wsh_tmp(
            ID,
            FLAG,
            COLUMN1)
           SELECT l_pickup_location_id_tbl(i), 'P', to_char(nvl(p_sc_pickup_date,l_sysdate), 'DD-MM-RRRR HH24:MI:SS')
           FROM   dual
           WHERE  NOT EXISTS (
                    select 'x'
                    from  wsh_tmp wt1
                    where wt1.id = l_pickup_location_id_tbl(i)
                    and   wt1.flag='P'
                    and   wt1.column1 = to_char(nvl(p_sc_pickup_date,l_sysdate), 'DD-MM-RRRR HH24:MI:SS'))
           UNION
           SELECT l_dropoff_location_id_tbl(i), 'D', to_char(nvl(p_sc_dropoff_date,l_sysdate), 'DD-MM-RRRR HH24:MI:SS')
           FROM   dual
           WHERE  NOT EXISTS (
                    select 'x'
                    from  wsh_tmp wt1
                    where wt1.id = l_dropoff_location_id_tbl(i)
                    and   wt1.flag='D'
                    and   wt1.column1 = to_char(nvl(p_sc_dropoff_date,l_sysdate), 'DD-MM-RRRR HH24:MI:SS'));
Line: 565

           INSERT INTO wsh_tmp(
            ID,
            FLAG,
            COLUMN1)
           SELECT l_pickup_location_id_tbl(i), 'P', to_char(nvl(l_pickup_date_tbl(i),l_sysdate), 'DD-MM-RRRR HH24:MI:SS')
           FROM   dual
           WHERE  NOT EXISTS (
                    select 'x'
                    from  wsh_tmp wt1
                    where wt1.id = l_pickup_location_id_tbl(i)
                    and   wt1.flag='P'
                    and   wt1.column1 = to_char(nvl(l_pickup_date_tbl(i),l_sysdate), 'DD-MM-RRRR HH24:MI:SS'))
           UNION
           SELECT l_dropoff_location_id_tbl(i), 'D', to_char(nvl(l_dropoff_date_tbl(i),l_sysdate), 'DD-MM-RRRR HH24:MI:SS')
           FROM   dual
           WHERE  NOT EXISTS (
                    select 'x'
                    from  wsh_tmp wt1
                    where wt1.id = l_dropoff_location_id_tbl(i)
                    and   wt1.flag='D'
                    and   wt1.column1 = to_char(nvl(l_dropoff_date_tbl(i),l_sysdate), 'DD-MM-RRRR HH24:MI:SS'));
Line: 589

       DELETE FROM wsh_tmp wt1
       WHERE  wt1.flag = 'P'
       AND    exists (
               select 'x'
               from   wsh_tmp wt2
               where  wt1.id = wt2.id
               and    wt2.flag = 'P'
               and    to_date(wt2.column1,'DD-MM-RRRR HH24:MI:SS') < to_date(wt1.column1,'DD-MM-RRRR HH24:MI:SS'));
Line: 599

       DELETE FROM wsh_tmp wt1
       WHERE  wt1.flag = 'D'
       AND    exists (
               select 'x'
               from   wsh_tmp wt2
               where  wt1.id = wt2.id
               and    wt2.flag = 'D'
               and    to_date(wt2.column1,'DD-MM-RRRR HH24:MI:SS') > to_date(wt1.column1,'DD-MM-RRRR HH24:MI:SS'));
Line: 614

             UPDATE wsh_tmp
             set    column2 = l_seq(i)
             WHERE  id = l_id(i);
Line: 830

               select column2, to_date(column1,'DD-MM-RRRR HH24:MI:SS')
               into   l_pickup_stop_seq,l_tmp_date
               from   wsh_tmp
               where  id = l_pickup_location_id
               and    flag = 'P';
Line: 1046

               p_action => 'UPDATE',
               x_return_status => l_return_status);
Line: 1097

            update wsh_trip_stops
            set planned_departure_date=least(nvl(l_pickup_date,sysdate),planned_departure_date),
            planned_arrival_date=least(nvl(l_pickup_date,sysdate),planned_arrival_date),
                   shipments_type_flag = l_stop_shipments_type_flag ,   -- J-IB-NPARIKH
                   last_update_date   = SYSDATE,    -- J-IB-NPARIKH
                   last_updated_by    = FND_GLOBAL.USER_ID,   -- J-IB-NPARIKH
                   last_update_login  = FND_GLOBAL.LOGIN_ID     -- J-IB-NPARIKH
            where stop_id=l_pickup_stop_id;
Line: 1115

        WSH_INTEGRATION.DBI_Update_Trip_Stop_Log
          (p_stop_id_tab	=> l_stop_tab,
           p_dml_type		=> 'UPDATE',
           x_return_status      => l_dbi_rs);
Line: 1238

               select column2,to_date(column1,'DD-MM-RRRR HH24:MI:SS')
               into   l_dropoff_stop_seq,l_tmp_date
               from   wsh_tmp
               where  id = l_dropoff_location_id
               and    flag = 'D';
Line: 1468

               p_action => 'UPDATE',
               x_return_status => l_return_status);
Line: 1519

            update wsh_trip_stops
            set    shipments_type_flag = l_stop_shipments_type_flag  ,  -- J-IB-NPARIKH
                   last_update_date   = SYSDATE,
                   last_updated_by    = FND_GLOBAL.USER_ID,
                   last_update_login  = FND_GLOBAL.LOGIN_ID
            where stop_id=l_dropoff_stop_id;
Line: 1615

            update wsh_delivery_legs
            set pick_up_stop_id = l_pickup_stop_id
            where delivery_leg_id = l_leg_id;
Line: 1634

	l_stop_tab.delete;
Line: 1636

        WSH_INTEGRATION.DBI_Update_Trip_Stop_Log
          (p_stop_id_tab	=> l_stop_tab,
           p_dml_type		=> 'UPDATE',
           x_return_status      => l_dbi_rs);
Line: 1663

            update wsh_delivery_legs
            set drop_off_stop_id = l_dropoff_stop_id
            where delivery_leg_id = l_leg_id;
Line: 1682

	l_stop_tab.delete;
Line: 1684

        WSH_INTEGRATION.DBI_Update_Trip_Stop_Log
          (p_stop_id_tab	=> l_stop_tab,
           p_dml_type		=> 'UPDATE',
           x_return_status      => l_dbi_rs);
Line: 1792

              update wsh_trip_stops
              set  planned_departure_date=p_pickup_dep_date,
                   planned_arrival_date=p_pickup_arr_date,
                   last_update_date   = SYSDATE,
                   last_updated_by    = FND_GLOBAL.USER_ID,
                   last_update_login  = FND_GLOBAL.LOGIN_ID
              where stop_id=p_pickup_stop_id;
Line: 1808

	l_stop_tab.delete;
Line: 1810

        WSH_INTEGRATION.DBI_Update_Trip_Stop_Log
          (p_stop_id_tab	=> l_stop_tab,
           p_dml_type		=> 'UPDATE',
           x_return_status      =>  l_dbi_rs);
Line: 1869

              update wsh_trip_stops
              set  planned_departure_date=p_dropoff_dep_date,
                   planned_arrival_date=p_dropoff_arr_date,
                   last_update_date   = SYSDATE,
                   last_updated_by    = FND_GLOBAL.USER_ID,
                   last_update_login  = FND_GLOBAL.LOGIN_ID
              where stop_id=p_dropoff_stop_id;
Line: 1885

	l_stop_tab.delete;
Line: 1887

        WSH_INTEGRATION.DBI_Update_Trip_Stop_Log
          (p_stop_id_tab	=> l_stop_tab,
           p_dml_type		=> 'UPDATE',
           x_return_status      => l_dbi_rs);
Line: 2057

               p_action => 'UPDATE',
               x_return_status => l_return_status);
Line: 2087

            update wsh_trip_stops
            set    shipments_type_flag = l_pu_stop_shipments_type_flag,    -- J-IB-NPARIKH
                   last_update_date   = SYSDATE,
                   last_updated_by    = FND_GLOBAL.USER_ID,
                   last_update_login  = FND_GLOBAL.LOGIN_ID
            where stop_id=l_pickup_stop_id;
Line: 2142

               p_action => 'UPDATE',
               x_return_status => l_return_status);
Line: 2171

            update wsh_trip_stops
            set    shipments_type_flag = l_do_stop_shipments_type_flag,    -- J-IB-NPARIKH
                   last_update_date   = SYSDATE,
                   last_updated_by    = FND_GLOBAL.USER_ID,
                   last_update_login  = FND_GLOBAL.LOGIN_ID
            where stop_id=l_dropoff_stop_id;
Line: 2231

            UPDATE WSH_TRIPS
            SET    shipments_type_flag = l_trip_shipments_type_flag_new, -- 'M',
                   last_update_date   = SYSDATE,
                   last_updated_by    = FND_GLOBAL.USER_ID,
                   last_update_login  = FND_GLOBAL.LOGIN_ID
            WHERE  trip_id             = p_trip_id;
Line: 2240

              UPDATE WSH_TRIP_STOPS
              SET    shipments_type_flag = l_trip_shipments_type_flag_new,
                     last_update_date   = SYSDATE,
                     last_updated_by    = FND_GLOBAL.USER_ID,
                     last_update_login  = FND_GLOBAL.LOGIN_ID
              WHERE  trip_id             = p_trip_id
              and    shipments_type_flag <> l_trip_shipments_type_flag_new;
Line: 2287

        p_update_del_flag    => 'Y',
        p_update_leg_flag    => 'N',
        x_leg_complete       => l_leg_complete,
        x_return_status      => l_return_status);
Line: 2871

SELECT   delivery_leg_id
FROM    wsh_delivery_legs
WHERE pick_up_stop_id = p_pickup_stop_id
FOR UPDATE NOWAIT;
Line: 2877

SELECT   delivery_leg_id
FROM    wsh_delivery_legs
WHERE drop_off_stop_id = p_dropoff_stop_id
FOR UPDATE NOWAIT;
Line: 2883

SELECT   dg.delivery_leg_id, st1.stop_location_id
FROM    wsh_trip_stops st1,
    wsh_trip_stops st2,
    wsh_delivery_legs dg
WHERE st1.stop_id = dg.pick_up_stop_id AND
    st2.stop_id = dg.drop_off_stop_id AND
    st1.trip_id = p_trip_id AND
    st2.trip_id = p_trip_id AND
    dg.delivery_id = p_del_id
FOR UPDATE NOWAIT;
Line: 2895

select status_code,
       nvl(shipment_direction,'O') shipment_direction
from wsh_new_deliveries
where delivery_id = c_del_id;
Line: 2903

select status_code,
       nvl(shipment_direction,'O') shipment_direction
from wsh_new_deliveries
where delivery_id = c_del_id;
Line: 2909

select status_code,
       nvl(shipment_direction,'O') shipment_direction,
       gross_weight,
       net_weight,
       volume, initial_pickup_location_id,
       organization_id
from wsh_new_deliveries
where delivery_id = c_del_id;
Line: 2920

  SELECT stop_id
  FROM   wsh_trip_stops
  WHERE  trip_id = p_trip_id;
Line: 2926

  SELECT count(*)
  FROM wsh_trip_stops a,wsh_delivery_legs b
  WHERE a.stop_id = b.pick_up_stop_id
  AND   a.trip_id = p_trip_id
  AND   rownum = 1 ;
Line: 2936

l_del_for_update_load_seq VARCHAR2(1); -- bug 6700792:OTM Dock Door App Sched Proj
Line: 3008

  l_del_for_update_load_seq := 'N';
Line: 3014

  SELECT 'Y'
  INTO   l_del_for_update_load_seq
  FROM   wsh_delivery_legs wdl,
         wsh_trip_stops wts,
         wsh_trips wt
  WHERE  wdl.delivery_id = p_del_rows(i)
  AND    wdl.drop_off_stop_id = wts.stop_id
  AND    wts.trip_id = wt.trip_id
  AND    wt.ignore_for_planning = 'N'
  AND    rownum = 1; --Bug 6884545
Line: 3027

  l_del_for_update_load_seq := 'N';
Line: 3179

        WSH_DEBUG_SV.logmsg(l_module_name,'Calling program unit WSH_DELIVERY_LEGS_PVT.DELETE_DELIVERY_LEG',WSH_DEBUG_SV.C_PROC_LEVEL);
Line: 3182

    wsh_delivery_legs_pvt.delete_delivery_leg(NULL,
                        l_del_leg_id, l_return_status);
Line: 3197

  IF (l_del_for_update_load_seq = 'Y' AND g_wms_installed(l_org_id) = 'Y') THEN

    DECLARE

    CURSOR c_lock_delivery_details (c_delivery_id IN number) IS
    SELECT wdd.delivery_detail_id
    FROM   wsh_delivery_assignments wda,
           wsh_delivery_details wdd
    WHERE  wda.delivery_id = c_delivery_id
    AND    wda.delivery_detail_id = wdd.delivery_detail_id
    FOR UPDATE OF wdd.load_seq_number NOWAIT;
Line: 3213

      l_del_det_tab.DELETE;
Line: 3222

        UPDATE wsh_new_deliveries
        SET    loading_sequence   = NULL,
               last_update_date   = SYSDATE,
               last_updated_by    = FND_GLOBAL.USER_ID,
               last_update_login  = FND_GLOBAL.LOGIN_ID
        WHERE  delivery_id = p_del_rows(i);
Line: 3230

          UPDATE  wsh_delivery_details
          SET     load_seq_number    = NULL,
                  last_update_date   = SYSDATE,
                  last_updated_by    = FND_GLOBAL.USER_ID,
                  last_update_login  = FND_GLOBAL.LOGIN_ID
          WHERE   delivery_detail_id = l_del_det_tab(i);
Line: 3590

    SELECT dlg.delivery_leg_id, trip.trip_id, trip.consolidation_allowed,
           trip.lane_id, trip.mode_of_transport
    FROM   wsh_delivery_legs dlg,
           wsh_delivery_assignments_v da,
           wsh_trips trip,
           wsh_trip_stops st
    WHERE  da.delivery_detail_id = c_delivery_detail_id AND
           da.delivery_id = dlg.delivery_id AND
           dlg.pick_up_stop_id = st.stop_id AND
           st.trip_id = trip.trip_id;
Line: 3602

  SELECT dlg.delivery_leg_id, trip.trip_id, trip.consolidation_allowed,
         trip.lane_id, trip.mode_of_transport
  FROM   wsh_delivery_legs dlg,
         wsh_trip_stops stop,
         wsh_trips  trip
  WHERE  dlg.delivery_id = c_delivery_id and
         dlg.pick_up_stop_id = stop.stop_id and
         stop.trip_id = trip.trip_id;
Line: 3612

  SELECT dlg.delivery_leg_id, trip.trip_id, trip.consolidation_allowed,
         trip.lane_id, trip.mode_of_transport
  FROM   wsh_delivery_legs   dlg,
         wsh_trip_stops      stop,
         wsh_trips           trip
  WHERE  dlg.delivery_leg_id = c_leg_id AND
         dlg.pick_up_stop_id = stop.stop_id AND
         stop.trip_id = trip.trip_id;
Line: 3623

 SELECT dlg.delivery_leg_id, trip.trip_id, trip.consolidation_allowed,
        trip.lane_id, trip.mode_of_transport
 FROM   wsh_trip_stops stop,
        wsh_trips      trip,
        wsh_delivery_legs dlg,
        wsh_trip_stops ts
 WHERE  stop.stop_id = c_stop_id AND
        stop.trip_id = trip.trip_id AND
        ts.trip_id=trip.trip_id AND
        dlg.pick_up_stop_id = ts.stop_id;
Line: 3635

 SELECT dlg.delivery_leg_id, trip.trip_id, trip.consolidation_allowed,
        trip.lane_id, trip.mode_of_transport
 FROM   wsh_trip_stops ts,
        wsh_delivery_legs dlg,
        wsh_trips trip
 WHERE  ts.trip_id = c_trip_id AND
        dlg.pick_up_stop_id = ts.stop_id AND
        ts.trip_id = trip.trip_id;
Line: 3645

 select 1
 from   wsh_freight_costs wfc,
        wsh_trip_stops    wts,
        wsh_delivery_legs wdl
 where  wts.trip_id         = c_trip_id
 and    wdl.pick_up_stop_id = wts.stop_id
 and    wfc.delivery_leg_id = wdl.delivery_leg_id
 and    wfc.line_type_code  = 'SUMMARY'
 and    wfc.delivery_detail_id is null
 and    NVL(wfc.total_amount,0) > 0;
Line: 3658

 select NVL(wfc.total_amount,0) price
 from   wsh_freight_costs wfc
 where  wfc.delivery_leg_id = c_dleg_id
 and    wfc.line_type_code  = 'SUMMARY'
 and    wfc.delivery_detail_id is null
 and    NVL(wfc.total_amount,0) > 0;
Line: 3666

 SELECT delivery_leg_id, status_code, reprice_required, parent_delivery_leg_id
 FROM wsh_delivery_legs
 WHERE delivery_leg_id = c_delivery_leg_id FOR UPDATE OF reprice_required NOWAIT;
Line: 3672

 SELECT mode_of_transport, lane_id
 --SELECT consolidation_allowed, lane_id
 FROM wsh_trips
 WHERE trip_id = c_trip_id;
Line: 3735

      l_del_leg_tab.delete;
Line: 3736

      l_final_leg_tab.delete;
Line: 3939

             UPDATE wsh_delivery_legs
             SET reprice_required = 'Y'
             WHERE CURRENT OF c_lock_delivery_leg;
Line: 3959

                UPDATE wsh_delivery_legs
                SET reprice_required = 'Y'
                WHERE delivery_leg_id =  l_lock_delivery_leg_rec.parent_delivery_leg_id
                AND NVL(reprice_required, 'N') <> 'Y';
Line: 4037

select freight_terms_code, nvl(shipment_direction, 'O')
from wsh_new_deliveries where delivery_id = p_del_id;
Line: 4187

select wnd.delivery_id
FROM   wsh_new_deliveries wnd,
       wsh_trip_stops wts,
       wsh_delivery_legs wdl
WHERE  wts.stop_id = wdl.pick_up_stop_id AND
       wts.trip_id = p_trip_id AND
       wdl.delivery_id = wnd.delivery_id AND
       wnd.freight_terms_code <> p_freight_terms_code_o and
       NVL(wnd.shipment_direction, 'O') IN ('O', 'IO')
       and rownum = 1
UNION
select wnd.delivery_id
FROM   wsh_new_deliveries wnd,
       wsh_trip_stops wts,
       wsh_delivery_legs wdl
WHERE  wts.stop_id = wdl.pick_up_stop_id AND
       wts.trip_id = p_trip_id AND
       wdl.delivery_id = wnd.delivery_id AND
       wnd.freight_terms_code <> p_freight_terms_code_i and
       wnd.shipment_direction = 'I'
       and rownum = 1
UNION
select wnd.delivery_id
FROM   wsh_new_deliveries wnd,
       wsh_trip_stops wts,
       wsh_delivery_legs wdl
WHERE  wts.stop_id = wdl.pick_up_stop_id AND
       wts.trip_id = p_trip_id AND
       wdl.delivery_id = wnd.delivery_id AND
       wnd.freight_terms_code <> p_freight_terms_code_d and
       wnd.shipment_direction = 'D'
       and rownum = 1;
Line: 4222

select wnd.delivery_id
FROM   wsh_new_deliveries wnd,
       wsh_trip_stops wts,
       wsh_delivery_legs wdl
WHERE  wts.stop_id = wdl.pick_up_stop_id AND
       wts.trip_id = p_trip_id AND
       wdl.delivery_id = wnd.delivery_id AND
       wnd.freight_terms_code = p_freight_terms_code_o and
       NVL(wnd.shipment_direction, 'O') IN ('O', 'IO')
       and rownum = 1
UNION
select wnd.delivery_id
FROM   wsh_new_deliveries wnd,
       wsh_trip_stops wts,
       wsh_delivery_legs wdl
WHERE  wts.stop_id = wdl.pick_up_stop_id AND
       wts.trip_id = p_trip_id AND
       wdl.delivery_id = wnd.delivery_id AND
       wnd.freight_terms_code <> p_freight_terms_code_i and
       wnd.shipment_direction = 'I'
       and rownum = 1
UNION
select wnd.delivery_id
FROM   wsh_new_deliveries wnd,
       wsh_trip_stops wts,
       wsh_delivery_legs wdl
WHERE  wts.stop_id = wdl.pick_up_stop_id AND
       wts.trip_id = p_trip_id AND
       wdl.delivery_id = wnd.delivery_id AND
       wnd.freight_terms_code <> p_freight_terms_code_d and
       wnd.shipment_direction = 'D'
       and rownum = 1;