Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7530553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:56:30+00:00 2026-05-30T04:56:30+00:00

I could use some pointers on my query I have three external tables that

  • 0

I could use some pointers on my query I have three external tables that i need to combine and create a .dat-file. But my query isn’t very efficient and could use some help on fixing/improving this one. It consist of two part one main table which is dc_item_loc_sourcing (1) and two translation tables dc_ccn190_sid_vtb(2) and dc_item_loc_vert_pim(3). If the item + loc combination doesn’t exist in 1 & 2 it should check 1 & 3.

SET heading OFF;    
SET feedback OFF; 
SET verify OFF; 
SET echo OFF;
SET linesize 1000;  
SET trimspool ON;
SET termout OFF;
SET newpage NONE;
SPOOL ../data/dc_sourcing.dat; 

SELECT DISTINCT TO_CHAR(item)
  || '|' ||store
  || '|' ||source_method
  || '|' ||primary_supp
  || '|' ||source_wh
  || '|' ||actie
  || '|' ||reward_eligible_ind
FROM ((SELECT dpac_tbl.item
      ,st.store
      ,dc_iloc.source_method
      ,dc_iloc.primary_supp
      ,dc_iloc.source_wh
      ,dc_iloc.actie
      ,dc_iloc.reward_eligible_ind
      ,MAX(dc_iloc.source_method) OVER (PARTITION BY dpac_tbl.item,st.store) max_src_pack
    FROM dc_item_loc_sourcing dc_iloc ,
      dc_ccn190_sid_vtb dpac_tbl ,
      store st ,
      item_master im ,
      item_loc il
    WHERE dc_iloc.dpac                         = dpac_tbl.dpac
    AND dpac_tbl.item                          = im.item
    AND CAST(dc_iloc.loc AS VARCHAR2(150byte)) = st.store_name_secondary
    AND st.store                               = il.loc
    AND dpac_tbl.item                          = il.item
    AND im.status                              = 'A'
    AND st.store_close_date                   >= SYSDATE
    AND il.status                              = 'A'
    AND dpac_tbl.ITEM NOT                     IN
      (SELECT IA.ITEM
      FROM ITEM_ATTRIBUTES IA
      WHERE IA.SH_STORE_ORDER_UNIT = 'N'
      AND IA.SH_TRADE_UNIT         = 'Y')
    UNION
    SELECT DISTINCT pi.item
      ,st.store
      ,dc_iloc.source_method
      ,dc_iloc.primary_supp
      ,dc_iloc.source_wh
      ,dc_iloc.actie
      ,dc_iloc.reward_eligible_ind
          ,MAX(dc_iloc.source_method) OVER (PARTITION BY pi.item,st.store) max_src_pack
    FROM dc_item_loc_sourcing dc_iloc ,
      dc_ccn190_sid_vtb dpac_tbl ,
      store st ,
      packitem pi ,
      item_master im ,
      item_loc il
    WHERE dc_iloc.dpac                         = dpac_tbl.dpac
    AND pi.pack_no                             = dpac_tbl.item
    AND pi.item                                = im.item
    AND CAST(dc_iloc.loc AS VARCHAR2(150byte)) = st.store_name_secondary
    AND il.item                                = pi.item
    AND il.loc                                 = st.store
    AND im.status                              = 'A'
    AND im.dept NOT                           IN (900,910,920,930)
    AND st.store_close_date                   >= SYSDATE
    AND il.status                              = 'A'
    AND PI.ITEM NOT                           IN
      (SELECT IA.ITEM
      FROM ITEM_ATTRIBUTES IA
      WHERE IA.SH_STORE_ORDER_UNIT = 'N'
      AND IA.SH_TRADE_UNIT         = 'Y'))
UNION
      (SELECT dpac_tbl.item ,
      st.store ,
      dc_iloc.source_method ,
      dc_iloc.primary_supp ,
      dc_iloc.source_wh ,
      dc_iloc.actie ,
      dc_iloc.reward_eligible_ind
      ,MAX(dc_iloc.source_method) OVER (PARTITION BY dpac_tbl.item,st.store) max_src_pack
    FROM dc_item_loc_sourcing dc_iloc ,
      dc_item_loc_vert_pim dpac_tbl ,
      store st ,
      item_master im ,
      item_loc il
    WHERE dc_iloc.dpac                          = dpac_tbl.dpac
    AND dpac_tbl.item                           = im.item
    AND CAST(dc_iloc.loc AS VARCHAR2(150 byte)) = st.store_name_secondary
    AND il.item                                 = dpac_tbl.item
    AND il.loc                                  = st.store
    AND im.status                               = 'A'
    AND dpac_tbl.artikel_type_lms NOT          IN ('V','S')
    AND st.store_close_date                    >= SYSDATE
    AND il.status                               = 'A'
    AND inventory_item_status_code             = 'Active'
    AND dpac_tbl.ITEM NOT                      IN
      (SELECT IA.ITEM
      FROM ITEM_ATTRIBUTES IA
      WHERE IA.SH_STORE_ORDER_UNIT = 'N'
      AND IA.SH_TRADE_UNIT         = 'Y')
    UNION
    SELECT DISTINCT pi.item ,
      st.store ,
      dc_iloc.source_method ,
      dc_iloc.primary_supp ,
      dc_iloc.source_wh ,
      dc_iloc.actie ,
      dc_iloc.reward_eligible_ind
          ,MAX(dc_iloc.source_method) OVER (PARTITION BY pi.item,st.store) max_src_pack

    FROM dc_item_loc_sourcing dc_iloc ,
      dc_item_loc_vert_pim dpac_tbl ,
      store st ,
      packitem pi ,
      item_master im ,
      item_loc il
    WHERE dc_iloc.dpac                          = dpac_tbl.dpac
    AND pi.pack_no                              = dpac_tbl.item
    AND pi.item                                 = im.item
    AND CAST(dc_iloc.loc AS VARCHAR2(150 byte)) = st.store_name_secondary
    AND il.item                                 = pi.item
    AND il.loc                                  = st.store
    AND im.status                               = 'A'
    AND dpac_tbl.artikel_type_lms NOT          IN ('V','S')
    AND im.dept NOT                            IN (900,910,920,930)
    AND st.store_close_date                    >= SYSDATE 
    AND il.status                               = 'A'
    AND inventory_item_status_code             = 'Active'
    AND pi.ITEM NOT                            IN
      (SELECT IA.ITEM
      FROM ITEM_ATTRIBUTES IA
      WHERE IA.SH_STORE_ORDER_UNIT = 'N'
      AND IA.SH_TRADE_UNIT         = 'Y'))) 
    WHERE source_method = max_src_pack;


SPOOL OFF;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T04:56:32+00:00Added an answer on May 30, 2026 at 4:56 am

    This hasn’t been tested – I’m away from an SQL instance at the moment, and obviously I don’t have access to your tables. I also don’t make any guarantee about performance, as I don’t know about current indicies.

    Your biggest problem appears to stem from using the implicit-join syntax. Don’t use it, it’s an anti-pattern; it also allows for some ‘surprising’ behaviour. Always explicitly specify your joins, and put (as many as possible) relevant conditions in the ON clause – only use the WHERE clause when dealing with the table reference in the FROM clause.

    I also have a huge problem with this line:
    AND CAST(dc_iloc.loc AS VARCHAR2(150byte)) = st.store_name_secondary
    You will not (likely… there are some caveats) be using an index on this comparison, which won’t help. It’s also a terrible thing, semantically, to join on – why is an item-location table keyed by (apparently) the store name? It should by keyed by store id – which should be the same datatype (no conversions), and should be the internal id, not something as transient as a ‘name’.

    WITH Excluded_Item (item) as (SELECT DISTINCT item
                                  FROM Item_Attributes
                                  WHERE sh_store_order_unit = 'N'
                                  AND sh_trade_unit = 'Y'), -- These should be 1/0 flags
                                                            -- (char or numeric)
                                                            -- or boolean, if supported
    
    SELECT CAST(item as CHAR) 
           || '|' || loc 
           || '|' || source_method 
           || '|' || primary_supp 
           || '|' || source_wh 
           || '|' || actie 
           || '|' || reward_eligible_ind 
    
    FROM(SELECT DISTINCT c.item, c.loc,
                         a.source_method, a.primary_supp, a.source_wh, a.actie,
                         a.reward_eligible_ind,
                         MAX(a.source_method) 
                         OVER(PARTITION BY c.item, c.loc) as maxSourcePack
                                     -- this should be indexed
         FROM dc_item_loc_sourcing as a
         JOIN store as b
         ON b.store_name_secondary = CAST(a.loc as VARCHAR2(150 byte))
         AND b.store_close_date >= CURRENT_DATE
         JOIN item_loc as c
         ON c.loc = b.store
         AND c.status = 'A'
         JOIN item_master as d
         ON d.status = 'A'
         AND d.item = c.item
         LEFT JOIN Excluded_Item as e
         ON e.item = d.item
         LEFT JOIN dc_ccn190_sid_vtb as f
         ON f.dpac = a.dpac
         LEFT JOIN dc_item_loc_vert_pim as g
         ON g.dpac = a.dpac
         AND g.artikel_type_lms NOT IN ('V', 'S')
         AND inventory_item_status_code = 'Active' -- really?  And where is this from? 
         LEFT JOIN packitem as h
         ON (h.pack_no = f.item OR h.pack_no = g.item)
         AND h.item = d.item
         AND d.dept NOT IN (900, 910, 920, 930)
         WHERE e.item IS NULL
         AND (h.item IS NOT NULL
              OR (h.item IS NULL AND (f.item = d.item OR g.item = d.item))) ) as h
    
    WHERE source_method = maxSourcepack
    

    I believe this is correct, although a definition of your tables (and sample data) would help immensely in this regard – especially in how packitem is defined.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a piece of code here that i really could use some help
I could use some help creating an XSL template that will take a string
We're having a small issue and could use some help - we have the
i have an issue i could use some help with, i have python list
I've inherited a rather large application that really could use some cleanup. There is
could anybody possibly give me some pointers as to the appropriate method to use
Django newbie at work and I could use some pointers. I'm using django-profile and
I have .so files that inside of them use some STL containers. Problem is
I could use some help writing a regular expression. In my Django application, users
I am getting the following error and could use some help resolving it. Anyone

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.