Quantcast
Channel: SCN : Unanswered Discussions - SAP Crystal Reports
Viewing all articles
Browse latest Browse all 4814

Linking tables in multiple DBs

$
0
0

Hi,

 

I have a report that links tables from an Order (ALFAK) DB with a production (alcim) DB.  In DB Expert I've joined Orders to Production by a left join from Orders Detail (BW_AUFTR_STKL) to Production History (awbar_historie) on Order Number (ID -> auftr) and Line Number (POS_NR -> pos).  Left join is so I can report on Orders that have not yet gone to production.

 

The SQL Query (fyi) generated is as follows:

 

ALFAKODBC

SELECT DISTINCT "BW_AUFTR_KOPF"."AH_NAME1", "BW_AUFTR_KOPF"."ID", "BW_AUFTR_KOPF"."DATUM_ERF", "BW_AUFTR_KOPF"."DATUM_ANLIEFERUNG", "BW_AUFTR_POS"."POS_NR", "KA_BESCHAFFUNGSART_P"."BEZ", "KA_BESCHAFFUNGSART_P"."ID", "BW_AUFTR_STKL"."ID", "BW_AUFTR_STKL"."POS_NR", "BW_AUFTR_STKL"."FER_BESCHAFFARTNR", "BW_AUFTR_STKL"."FER_BESCHAFFARTTYP"

FROM   (("GGIMAIN"."SYSADM"."BW_AUFTR_KOPF" "BW_AUFTR_KOPF" LEFT OUTER JOIN "GGIMAIN"."SYSADM"."BW_AUFTR_POS" "BW_AUFTR_POS" ON "BW_AUFTR_KOPF"."ID"="BW_AUFTR_POS"."ID") LEFT OUTER JOIN "GGIMAIN"."SYSADM"."KA_BESCHAFFUNGSART" "KA_BESCHAFFUNGSART_P" ON ("BW_AUFTR_POS"."FER_BESCHAFFARTNR"="KA_BESCHAFFUNGSART_P"."ID") AND ("BW_AUFTR_POS"."FER_BESCHAFFARTTYP"="KA_BESCHAFFUNGSART_P"."TYP")) LEFT OUTER JOIN "GGIMAIN"."SYSADM"."BW_AUFTR_STKL" "BW_AUFTR_STKL" ON ("BW_AUFTR_POS"."ID"="BW_AUFTR_STKL"."ID") AND ("BW_AUFTR_POS"."POS_NR"="BW_AUFTR_STKL"."POS_NR")

ORDER BY "BW_AUFTR_KOPF"."AH_NAME1", "BW_AUFTR_POS"."POS_NR"

EXTERNAL JOIN BW_AUFTR_STKL.ID={?alcimdb: awbar_historie.auftnr} AND BW_AUFTR_STKL.POS_NR={?alcimdb: awbar_historie.pos} AND BW_AUFTR_STKL.FER_BESCHAFFARTNR={?ALFAKODBC: KA_BESCHAFFUNGSART_S.ID} AND BW_AUFTR_STKL.FER_BESCHAFFARTTYP={?ALFAKODBC: KA_BESCHAFFUNGSART_S.TYP}

 

alcimdb

SELECT DISTINCT "awbar_historie"."etikettnr", "awbar_historie"."zeit", "awbar_historie"."sequence", "awbar_historie"."esname", "awbar_historie"."esnr", "awbar_historie"."pos", "awbar_historie"."auftnr"

FROM   "alcimdb"."dbo"."awbar_historie" "awbar_historie"

WHERE  "awbar_historie"."auftnr"={?ALFAKODBC: BW_AUFTR_STKL.ID} AND "awbar_historie"."pos"={?ALFAKODBC: BW_AUFTR_STKL.POS_NR}

ORDER BY "awbar_historie"."etikettnr", "awbar_historie"."zeit"

 

ALFAKODBC

SELECT DISTINCT "KA_BESCHAFFUNGSART_S"."BEZ", "KA_BESCHAFFUNGSART_S"."ID", "KA_BESCHAFFUNGSART_S"."TYP"

FROM   "GGIMAIN"."SYSADM"."KA_BESCHAFFUNGSART" "KA_BESCHAFFUNGSART_S"

WHERE  "KA_BESCHAFFUNGSART_S"."ID"={?ALFAKODBC: BW_AUFTR_STKL.FER_BESCHAFFARTNR} AND "KA_BESCHAFFUNGSART_S"."TYP"={?ALFAKODBC: BW_AUFTR_STKL.FER_BESCHAFFARTTYP}

 

Report seemed to give me what I want, but was running slow, as it usually does when I use multiple DBs.

 

So I recreated in a similar manner with a Command:

 

select distinct K.AH_NAME1 'Customer', K.ID 'Order', K.DATUM_ERF 'Ord Entry', K.DATUM_ANLIEFERUNG 'Ord Delivery',

                P.POS_NR 'Line', K_P.ID 'Pos Procure Typ', K_P.BEZ 'Pos Procure', K_S.ID 'BOM Procure Typ', K_S.BEZ 'BOM Procure',

                H.ETIKETTNR 'Barcode', H.ZEIT 'Reg Time', H.SEQUENCE 'Responsible Booking', H.ESNR 'Reg Pnt #', H.ESNAME 'Reg Point', H.POS 'Line # Hist'

from GGIMAIN.SYSADM.BW_AUFTR_KOPF K

left join GGIMAIN.SYSADM.BW_AUFTR_POS P on K.ID = P.ID

left join GGIMAIN.SYSADM.BW_AUFTR_STKL S on P.ID = S.ID and P.POS_NR = S.POS_NR

left join GGIMAIN.SYSADM.KA_BESCHAFFUNGSART K_P on P.FER_BESCHAFFARTNR = K_P.ID and P.FER_BESCHAFFARTTYP = K_P.TYP

left join GGIMAIN.SYSADM.KA_BESCHAFFUNGSART K_S on S.FER_BESCHAFFARTNR = K_S.ID and S.FER_BESCHAFFARTTYP = K_S.TYP

left join ALCIMDB.DBO.AWBAR_HISTORIE H on S.ID = H.AUFTNR and S.POS_NR = H.POS

where K_P.ID = 7 or K_S.ID = 7

order by K.AH_NAME1, P.POS_NR, H.ETIKETTNR, H.ZEIT

 

With the command. I can now see that it wasn't reporting Orders that have not been released to Production.

 

I've never really been able to wrap my brain around the code that's generated when there are multiple DBs.  Can anyone give me some pointers on deciphering, and any insights into why it doesn't seem to respect the left join that I've created?

 

Any thought would be helpful.

 

Thanks!

 

MAtt


Viewing all articles
Browse latest Browse all 4814

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>