Need to specify LEFT OUTER JOIN while using data from logical database BRM?
I'm trying to extract data for external processing using SQVI. The fields required are in tables BKPF (Document Header) and BSEG (document detail) so I'm using logical database BRM. Note: required fields include the SPGR* (blocking reasons) which don't appear to be in BSIS/BSAS/BSID/BSAD/BSIK/BSAK, hence I can't just use a Table Join on any of these but have to use BSEG, hence BRM.
If the document type is an invoice, I also need to include the PO number from table EKKO (PO header), if present, hence I'd like to add this to the list. However, if I do this, it seems that some records are no longer display, e.g. AB documents.
The interesting thing is that not all records are suppressed, so it's not a simple case of the logical database using an effective INNER JOIN, but the effect is similar.
In any event, is there a way to specify that the link to table EKKO should be treated as an effective LEFT OUTER JOIN, i.e. records from BKPF/BSEG should be included irrespective of whether any records from EKKO/EKPO exist or not?
Alternatively, is there some other way to get the SPGR* fields (for example) from BSEG and still join the BKPF? Of course, one solution is to use multiple queries, but I was hoping to avoid this.
Thanks for everyone's responses, I know how to work around the problem with sql, I am wanting to see if there is a way to make the outer joins filter go in the join clause instead of the where clause with Crystal Reports standard functionality.
We have some Crystal Reports users that are not sql users, i.e. benefit specialists, payroll specialists and compensation analysts who have Crystal Reports. I was hoping this functionality was available for them. I just made my example a simple one, but often reports have multiple outer joins with maybe 2 or three of the outer joins needing a filter on them that won't make them into an inner join.
Such as
Select person information
outer join address record
outer join email record
outer join tax record (filter for active state record & filter for code = STATE )
outer join pay rates record
outer join phone#s (filter for home phone#)
I thought maybe the functionality may be available, that I just don't know how or where to use it. Maybe it is just not available.
If it is not available, I will probably need to setup some standard views for them to query, rather than expecting them to pull the tables together themselves.
Similar Messages
-
How to Specify Left Outer Join in OWB
If I run the query:
select s.school_id,
nvl(max(decode(cv.cat_id, 'UCL', cv.long_desc, null)),'Unknown') UCL,
nvl(max(decode(cv.cat_id, 'REGION', cv.long_desc, null)),'Unknown') REGION,
nvl(max(decode(cv.cat_id, 'TREASREG', cv.long_desc, null)),'Unknown') TREASREG,
nvl(max(decode(cv.cat_id, 'RELGN', cv.long_desc, null)),'Unknown') RELGN,
nvl(max(decode(cv.cat_id, 'NGEFF', cv.long_desc, null)),'Unknown') NGEFF,
nvl(max(decode(cv.cat_id, 'PCAP', cv.long_desc, null)),'Unknown') PCAP,
nvl(max(decode(cv.cat_id, 'ATSIC', cv.long_desc, null)),'Unknown') ATSIC
from sdw.sdr_schools s
left outer join
sdw.sdr_school_category_values scv on s.school_id = scv.school_id
left outer join
sdw.sdr_category_values cv on cv.cat_id = scv.cat_id
and cv.cat_value_id = scv.cat_value_id
group by s.school_id
order by s.school_id
I get 1706 records. In OWB I get 1656 records.
In OWB I use a JOIN for the three tables, then an expression for the decode lines and sort and then the final table. In the SQL above, if the second left outer join is removed I get 1656 records?
Ho do you force OWB to produce 1706 records?You have to use the (+) notation.
e.g.
table1.column1 (+) = table2.column1
Also, you can do a full-outer-join using table1.column1 (+) = table2.column1 (+) even though this is not legal SQL*Plus syntax. -
Time Out Dump while extracting data from table CKIS
Dear Friends,
I am getting TIme Out dump for the below code, while extracting data from table CKIS.
Table CKIS doesn't have any Indexes. Please guide me to resolve this.
Regards,
Viji.
form get_keko_ckis.
SELECT kalnr kalka kadky tvers bwvar matnr werks kokrs
FROM keko
INTO TABLE i_keko1
FOR ALL ENTRIES IN i_final_modify
WHERE matnr = i_final_modify-main_f
AND werks = p_werks
AND kokrs = p_kokrs
AND kadat = p_kadat
AND bidat = p_bidat
AND bwdat = p_bwdat.
IF sy-subrc = 0.
SORT i_keko1 BY kalnr kalka kadky tvers bwvar.
SELECT kalnr kalka kadky tvers bwvar posnr typps kstar
matnr menge gpreis
FROM ckis
INTO TABLE i_ckis_temp
FOR ALL ENTRIES IN i_keko1
WHERE kalnr = i_keko1-kalnr
AND kalka = i_keko1-kalka
AND kadky = i_keko1-kadky
AND tvers = i_keko1-tvers
AND bwvar = i_keko1-bwvar.
IF sy-subrc = 0.
SORT i_ckis_temp BY kalnr kalka kadky tvers bwvar.
LOOP AT i_ckis_temp INTO wa_ckis_temp.
wa_ckis-kalnr = wa_ckis_temp-kalnr.
wa_ckis-kadky = wa_ckis_temp-kadky.
wa_ckis-posnr = wa_ckis_temp-posnr.
wa_ckis-typps = wa_ckis_temp-typps.
wa_ckis-kstar = wa_ckis_temp-kstar.
wa_ckis-matnr1 = wa_ckis_temp-matnr1.
wa_ckis-menge = wa_ckis_temp-menge.
wa_ckis-gpreis = wa_ckis_temp-gpreis.
CLEAR wa_keko1.
READ TABLE i_keko1 INTO wa_keko1
WITH KEY kalnr = wa_ckis_temp-kalnr
kalka = wa_ckis_temp-kalka
kadky = wa_ckis_temp-kadky
tvers = wa_ckis_temp-tvers
bwvar = wa_ckis_temp-bwvar
BINARY SEARCH.
IF sy-subrc = 0.
wa_ckis-matnr = wa_keko1-matnr.
wa_ckis-werks = wa_keko1-werks.
ENDIF.
APPEND wa_ckis TO i_ckis.
CLEAR: wa_ckis_temp, wa_ckis.
ENDLOOP.
ENDIF.
REFRESH: i_keko1, i_ckis_temp.
ENDIF.
endform. " get_keko_ckisHi Try minimising the conditions in where clause
SELECT fields..... FROM CKIS
WHERE KALNR = KEKO-KALNR AND
KADKY = KEKO-KADKY AND
TVERS = KEKO-TVERS AND
TYPPS = 'M'.
after this, deleting unwanted records from internal table as per pending conditions...
Regds,
Anil -
Error while fetching data from Logical data base
Hi All,
I need to fetch the data from Logical data base DDF.First when i am trying demo code
REPORT demo_program_read_tables_2.
NODES: spfli, sflight.
GET spfli FIELDS carrid connid cityfrom cityto.
WRITE: / spfli-carrid,
spfli-connid,
spfli-cityfrom,
spfli-cityto.
GET sflight FIELDS fldate.
WRITE: / sflight-fldate.
I am getting error like ""spfli is not a node of the logical data base __S""
Should i declare anything esle?
MadhuREPORT demo_logical_database.
DATA wa_spfli TYPE spfli.
SELECT-OPTIONS s_carr FOR wa_spfli-carrid.
DATA: callback TYPE TABLE OF ldbcb,
callback_wa LIKE LINE OF callback.
DATA: seltab TYPE TABLE OF rsparams,
seltab_wa LIKE LINE OF seltab.
callback_wa-ldbnode = 'SPFLI'.
callback_wa-get = 'X'.
callback_wa-get_late = 'X'.
callback_wa-cb_prog = sy-repid.
callback_wa-cb_form = 'CALLBACK_SPFLI'.
APPEND callback_wa TO callback.
CLEAR callback_wa.
callback_wa-ldbnode = 'SFLIGHT'.
callback_wa-get = 'X'.
callback_wa-cb_prog = sy-repid.
callback_wa-cb_form = 'CALLBACK_SFLIGHT'.
APPEND callback_wa TO callback.
seltab_wa-kind = 'S'.
seltab_wa-selname = 'CARRID'.
LOOP AT s_carr.
MOVE-CORRESPONDING s_carr TO seltab_wa.
APPEND seltab_wa TO seltab.
ENDLOOP.
CALL FUNCTION 'LDB_PROCESS'
EXPORTING
ldbname = 'F1S'
variant = ' '
TABLES
callback = callback
selections = seltab
EXCEPTIONS
ldb_not_reentrant = 1
ldb_incorrect = 2
ldb_already_running = 3
ldb_error = 4
ldb_selections_error = 5
ldb_selections_not_accepted = 6
variant_not_existent = 7
variant_obsolete = 8
variant_error = 9
free_selections_error = 10
callback_no_event = 11
callback_node_duplicate = 12
OTHERS = 13.
IF sy-subrc <> 0.
WRITE: 'Exception with SY-SUBRC', sy-subrc.
ENDIF.
FORM callback_spfli USING name TYPE ldbn-ldbnode
wa TYPE spfli
evt TYPE c
check TYPE c.
CASE evt.
WHEN 'G'.
WRITE: / wa-carrid, wa-connid, wa-cityfrom, wa-cityto.
ULINE.
WHEN 'L'.
ULINE.
ENDCASE.
ENDFORM.
FORM callback_sflight USING name TYPE ldbn-ldbnode
wa TYPE sflight
evt TYPE c
check TYPE c.
WRITE: / wa-fldate, wa-seatsocc, wa-seatsmax.
ENDFORM. -
LEFT OUTER JOIN multiple tables - using the 9i syntax
I've always written my queries using the (+) operator for outer joins. I want to start using the new ANSI standard available in 9i. I can do it when I'm joining two tables in a simple query, but how does it work when I am joining multiple tables?
Here is an example of some SQL that works with the (+) outer join syntax. How can I convert this to use the LEFT OUTER JOIN syntax?
SELECT *
FROM audit_entry aue,
audit_table aut,
audit_statement aus,
audit_row aur,
audit_row_pkey aup1,
audit_row_pkey aup2
WHERE aue.audit_entry_id = aus.audit_entry_id
AND aut.table_name = 'TEST_AUDITING'
AND aut.table_owner = 'CLA_JOURNAL'
AND aus.audit_table_id = aut.audit_table_id
AND aur.audit_statement_id (+) = aus.audit_statement_id
AND aup1.audit_row_id (+) = aur.audit_row_id
AND aup1.pk_column_name (+) = 'TEST_AUDTING_PK_1'
AND aup2.audit_row_id (+) = aur.audit_row_id
AND aup2.pk_column_name (+) = 'TEST_AUDITING_PK_2'
I can join audit_statement to audit_entry easy enough, but then I want to join audit_table to audit_statement, how do I do that, do I start nesting the join statements?
Thanks
RichardThanks for getting back so quickly, I have tried the suggested SQL with mixed results:
SELECT COUNT(*)
FROM audit_entry aue
JOIN audit_statement aus ON aue.audit_entry_id = aus.audit_entry_id
JOIN audit_table aut ON aus.audit_table_id = aut.audit_table_id
RIGHT OUTER JOIN audit_row aur ON aur.audit_statement_id = aus.audit_statement_id
RIGHT OUTER JOIN audit_row_pkey aup1 ON aup1.audit_row_id = aur.audit_row_id
RIGHT OUTER JOIN audit_row_pkey aup2 ON aup2.audit_row_id = aur.audit_row_id
WHERE aut.table_name = 'TEST_AUDITING_TWO'
AND aut.table_owner = 'CLA_JOURNAL'
AND aup1.pk_column_name = 'TEST_AUDTING_PK_1'
AND aup2.pk_column_name = 'TEST_AUDITING_PK_2'
I had to change the order slightly, between the first two JOINs but otherwise it executed OK. My problem is, it should only return 175 rows but its returning 30625 rows. If I comment out the second reference to audit_row_pkey I get the expected result:
SELECT COUNT(*)
FROM audit_entry aue
JOIN audit_statement aus ON aue.audit_entry_id = aus.audit_entry_id
JOIN audit_table aut ON aus.audit_table_id = aut.audit_table_id
RIGHT OUTER JOIN audit_row aur ON aur.audit_statement_id = aus.audit_statement_id
RIGHT OUTER JOIN audit_row_pkey aup1 ON aup1.audit_row_id = aur.audit_row_id
--RIGHT OUTER JOIN audit_row_pkey aup2 ON aup2.audit_row_id = aur.audit_row_id
WHERE aut.table_name = 'TEST_AUDITING_TWO'
AND aut.table_owner = 'CLA_JOURNAL'
AND aup1.pk_column_name = 'TEST_AUDTING_PK_1'
--AND aup2.pk_column_name = 'TEST_AUDITING_PK_2'
It looks the same condition is being used in each case but why do I suddenly get so many rows - its joining differently somehow. It must be to do with the order, do I need to bracket the query?
Thanks again
Richard -
Left outer join problem -- need feedback
using crystal 2008
haveing prolbems with a left outerjoin to get a blank field(null) to show up.
basically i have some po line have have long descriptions or text fields that i want to include with the report. Below is my sql statement. I have written a formula with a join between 2 fields to get the report to work- this does but- it leave the polines off that do not have a long description. I have tried left outer joins but seem to be having problems. The long description field where the data is actually at is under my po.line table, although serveral area have long description fields -
*one note i had to add a duplicate table to the field to get some items in my header to work properly - not sure if this is effecting the report or not.
OK- when I set up the link to a LO join enforce from = to
and dont add the ldtext.field to the report the left outjoin works(but no long description)and all my line items show up.
1. when I keep the same join and add either just the ld.text field to the report it comes back with a error saying invalid table
2. when i use my formula that joins the ld.text and po.line and place it in the report with the same left outerjoin i get the same failure.
3. when i dont reference the ldtext(field) at all in the report it works fine w/ the lo join
4. when i Dont use a left outer join and use my formula(see below)
if not isnull(({LONGDESCRIPTION.LDTEXT }))
then {POLINE.DESCRIPTION}+{LONGDESCRIPTION.LDTEXT}
else {POLINE.DESCRIPTION}
and link from poline.ld
to ld.ldtext - my formula works and populates the po.line and the ld.text together - except that any po.line with no description will not show up. Like its not there.
Not sure what to do?
here is my current sql statement with the longdescription field in the select statement
here is the error statement i am getting:
Failed to retrieve data from the database:
Details:42000[intersolv][odb sql base driver][sql base] 00906 itn invalid table name[database vendor code:906]
sql statement:
SELECT "PO"."PONUM", "PO"."STATUS", "PO"."VENDOR",
"COMPANIES"."NAME", "COMPANIES"."ADDRESS1",
"COMPANIES"."ADDRESS2", "COMPANIES"."ADDRESS3",
"COMPANIES"."ADDRESS4", "COMPANIES"."PHONE",
"COMPANIES"."FAX", "COMPANIES_1"."NAME",
"COMPANIES_1"."ADDRESS1", "COMPANIES_1"."ADDRESS2",
"COMPANIES_1"."ADDRESS3", "COMPANIES_1"."ADDRESS4",
"COMPANIES_1"."CONTACT", "COMPANIES_1"."PHONE",
"COMPANIES_1"."FAX", "PO"."PURCHASEAGENT",
"PO"."ORDERDATE",
"PO"."REQUIREDDATE", "PO"."PAYMENTTERMS",
"PO"."SHIPVIA", "PO"."FREIGHTTERMS", "PO"."FOB",
"POLINE"."DESCRIPTION", "POLINE"."ITEMNUM",
"POLINE"."ORDERQTY", "POLINE"."UNITCOST",
"POLINE"."LOADEDCOST", "POLINE"."POLINENUM",
"PO"."SHIPTOATTN", "LONGDESCRIPTION"."LDTEXT"
FROM ("MAXIMO"."PO" "PO" LEFT OUTER JOIN
"MAXIMO"."LONGDESCRIPTION" "LONGDESCRIPTION" ON "PO"."LDKEY"="LONGDESCRIPTION"."LDKEY"),
"MAXIMO"."POLINE" "POLINE",
"MAXIMO"."COMPANIES" "COMPANIES_1",
"MAXIMO"."COMPANIES" "COMPANIES"
WHERE ("PO"."PONUM"="POLINE"."PONUM") AND ("PO"."VENDOR"="COMPANIES_1"."COMPANY") AND ("PO"."SHIPTO"="COMPANIES"."COMPANY") AND "PO"."PONUM"='3386-053'If you took the time to read this thanks.... turns out... and I just want to pull my hair out over this. My connection had a old odbc driver so somehow it would not allow a left outer join....go figure - weeks of agony over that..... thanks ....have to say love this forum.
-
I have tables with index on it , i join them using left outer join. So the table access path choosen by the optimizer is full table access.
index not used in it. is there any other way to use index ? alternate to left outer join to use index ?
thanks
RajHi
I have tables with index on it , i join them using left outer join. So the table access path choosen by the optimizer is full table access.
index not used in it. is there any other way to use index ? alternate to left outer join to use index ?There are several ways, for this problem
1. May be your tables does't have statistics..do analyse tables.
2. Joining conditions are wrong.
3. Check Filter conditions.
KPR -
Error in making left outer join to a nested query
i am writing this query getting error here i am using nested query with that i am making join it is giving error
SQL
SELECT
* FROM IVItem INNER JOIN
IVPackSize_Mst ON IVItem.PackSizeID = IVPackSize_Mst.Id
left outer join IvItemGenericLink on IvItemGenericLink.itemID=IVItem.Id
Select GenericId from
IvItemGenericLink where ItemID=IVItem.Id and rownum <=1
)x
and x on IvItemGenericLink.GenericId=x.GenericId;
Error report:
SQL Error: ORA-00936: missing expression
00936. 00000 - "missing expression"
*Cause:
*Action:
give me and suggestioni am using left outer join at virtual table say x your gave me its equivalent
EXISTS (SELECT 1 FROM IvItemGenericLink G
WHERE G.ITEMID =V.ID
AND G.GenericId = L.GenericId)-----its i guess inner join
i am not confirmed that why iam asking this i guess i have to use this
as i use keyword inner join for inner join and for left join i use
left outer join
EXISTS (SELECT 1 FROM IvItemGenericLink G
WHERE G.ITEMID =V.ID
AND G.GenericId(+) = L.GenericId)-----its i guess left outer join
left outer join
Select GenericId from
IvItemGenericLink where ItemID=IVItem.Id and rownum <=1
)*x*
IvItemGenericLink.GenericId=x.GenericId
-------------------Statement U Gave in this--------------------------------------------------------------------------
SELECT *
FROM IVITEM V, IVPACKSIZE_MST M , IVITEMGENERICLINK L,
WHERE V.PACKSIZEID = M.ID
AND V.ID = L.ITEMID (+)
AND EXISTS (SELECT 1 FROM IvItemGenericLink G
WHERE G.ITEMID =V.ID
AND G.GenericId = L.GenericId)
-------------------Statement U Gave in this--------------------------------------------------------------------------
is this equivalent to left outer join
*AND EXISTS (
SELECT 1 FROM IvItemGenericLink G*
WHERE G.ITEMID =V.ID
*AND G.GenericId = L.GenericId
please tell me this in this regard -
How can I crate a view with tables which require "Left outer join"?
Hi guys,
how can I define a view with tables which require "Left outer join"?. In SE11 "View",->tab "Join condition", it seems that it valid only for "Inner Join".
Please give me some hint.
Thanks in advance.
Regards,
LiyingHi
Inner Join and Outer Join
The data that can be selected with a view depends primarily on whether the view implements an inner join or an outer join.
With an inner join, you only get the records of the cross-product for which there is an entry in all tables used in the view.
With an outer join, records are also selected for which there is no entry in some of the tables used in the view. (ABAP allows left outer join.)
The data that can be selected with a view depends primarily on whether the view implements an inner join or an outer join. -
How to fetch data from single database table using 2 internal tables.
Hi friends,
i am a new user of ABAP and also SDN.
i need a help.
i want to fetch data from one database table based on primary keys of 2 internal tables. how to put in where clause.
Thanks in advance.hii
refer to following code ..i hope it will help you
SELECT matnr " Material Number
FROM mara
INTO TABLE i_mara
WHERE matnr IN s_matnr.
IF i_mara[] IS NOT INITIAL.
SELECT matnr " Material Number
werks " Plants
prctr " Profit Center
FROM marc
INTO TABLE i_marc
FOR ALL ENTRIES IN i_mara
WHERE matnr = i_mara-matnr
AND werks IN s_werks.
ENDIF. " IF i_mara[] IS NOT INITIAL
i_output = i_marc.
IF i_marc[] IS NOT INITIAL.
SELECT matnr " Material Number
werks " Plants
lgort " Storage Location
FROM mard
INTO TABLE i_mard
FOR ALL ENTRIES IN i_marc
WHERE matnr EQ i_marc-matnr
AND werks EQ i_marc-werks
AND lgort IN s_lgort.
ENDIF. " IF i_mara[] IS NOT INITIAL
regards
twinkal -
Hi SAP,
I have an access database with table called "Employee_ID". I am linking this table to a table called "Sales" in our main database and trying to report on January 2009.
There is one employee that is not appearing in my report. I know this employee has had no sales in Jan 2009. So, I tried linking the table using Left Outer Join and still this employee is not appearing in my report.
As a test, when I bring in Employee_ID table alone, the missing employee appears but when I try linking it INNER or LEFT OUTER join to table Sales, this employee does not appear.
Any help how I can bring the employee in from table Employee_ID?
Many thanks in advance,
Zack H.Carl & Raghavendra,
Your suggestion led me to the finding my solution. Your suggestion brought back the missing employee but I needed all employees that had sales in January 2009 AND those that didn't. So I had to tweak your select expert formula as follows:
isnull({Sales.amt}) or
{Sales.period}="0109"
This brought back everything as needed! There was one negative about using this method. The performance was poor. It took a really long time to run.
To avoid having to wait for this to run and increase the performance, I had to go into the database and add a $0.00 sales amt for employee 2040 (or an empty sales amount record) in the month of January 2009. This brought back everyone also and it obviously increased the performance exponentially. Curious, why does it take forever to run using the above formula in select expert?
Thank you both Raghavendra and Carl for your relentless efforts to find a solution. You did it!
Zack H. -
Left outer join using date range returns too many rows
I am trying to pull data for a website.
Names table:
company_name varchar2(30)
julian_day varchar2(3)
logins number(3)
login_errors number(3)
Given a julian date range (e.g. 250-252), I am displaying the information from the Names table.
The problem is that I also need to display changes (increases/decreases) in the data. I do that by coloring the text based on a 10% increase/decrease. Data for the 3 days 250-252 would be compared to data for the previous 3 days 247-249.
Not all companies will report data on all days, so some gaps in the data may exist. Therefore, I cannot do just a simple join.
I am trying to write a query that will give me this information if the user chooses days 250-252.
Company_name
sum(logins) for days 250-252
sum(login_errors) for days 250-252
sum(logins) for days 247-249
sum(login_errors) for days 247-249
The query I'm using is:
select cur.company_name, sum(cur.logins),
sum(cur.login_errors), sum(old.logins), sum(old.login_errors)
FROM names cur LEFT OUTER JOIN names old
ON cur.company_name = old.company_name
WHERE cur.adate>='250' and cur.adate<='252'
and old.adate>='247' and old.adate<='249'
GROUP by cur.company_name
Given this data:
Company_name adate logins login_errors
ABC 247 10 10
ABC 248 20 20
ABC 249 30 30
ABC 250 15 15
ABC 251 25 25
ABC 252 35 35
My problem is that it returns:
adate cur.logins cur.login_err old.logins old.login_err
250 15 15 60 60
251 25 25 60 60
252 35 35 60 60
How can I get it to only give me the one "old" day's data? I went with the LEFT OUTER JOIN because it's possible that there is no data for an "old" day.
Thanks in advance.....Your problem stems from the join itself, and would be the same even without the OUTER JOIN. With your data, there are 3 records in cur and 3 records in old. The join matches each record in cur to each record in old resulting in 9 records in total. Without the SUM, this is clear:
SQL> SELECT cur.company_name, cur.logins, cur.login_errors,
2 old.logins, old.login_errors, cur.adate cad, old.adate oad
3 FROM names cur LEFT OUTER JOIN names old
4 ON cur.company_name = old.company_name
5 WHERE cur.adate>=250 and cur.adate<=252 and
6 old.adate>=247 and old.adate<=249;
COMPANY_NA LOGINS LOGIN_ERRORS LOGINS LOGIN_ERRORS CAD OAD
ABC 35 35 10 10 252 247
ABC 25 25 10 10 251 247
ABC 15 15 10 10 250 247
ABC 35 35 20 20 252 248
ABC 25 25 20 20 251 248
ABC 15 15 20 20 250 248
ABC 35 35 30 30 252 249
ABC 25 25 30 30 251 249
ABC 15 15 30 30 250 249
9 rows selected.You can do this with only one reference to the table.
SELECT company_name,
SUM(CASE WHEN adate BETWEEN 250 and 252 THEN logins ELSE 0 END) curlog,
SUM(CASE WHEN adate BETWEEN 250 and 252 THEN login_errors ELSE 0 END) curerr,
SUM(CASE WHEN adate BETWEEN 247 and 249 THEN logins ELSE 0 END) oldlog,
SUM(CASE WHEN adate BETWEEN 247 and 249 THEN login_errors ELSE 0 END) olderr
FROM names
WHERE adate BETWEEN 247 and 252
GROUP BY company_nameHTH
John -
Using Command to fix null / left outer join issue
Hi
I was told awhile ago that it's possible to fix crystal's issue with left outer join and null records being eliminated.
I think i remember most of how this goes, but i can't seem to duplicate it.
1) You can't have any select expert -- record
2) You create the report normally and then make a new report using the SQL Query
- Can't remember if its the whole report or upto the tables that have hisotry (null results)
3) You move parts from WHERE to FROM
Hopefully someone can help correct the steps i'm doing wrong or add what i'm missing from this.
Below is the Query from my comlpeted report, but when i run it with the last LEFT OUTER JOIN added it removes all the products with no sales during that year.
Any help would be greatly appreciated even if it's to say this can't be done.
SELECT
"prod_warehouse"."pw_whs_id",
"prod_warehouse"."pw_prodline_id",
"prod_warehouse"."pw_prod_id",
"prod_warehouse"."pw_bin_location1",
"prod_warehouse"."pw_min_onhand_qty",
"prod_warehouse"."pw_max_onhand_qty",
"prod_warehouse"."pw_onhand_qty",
"product_lookup"."prlkp_lang1_1_desc",
"prod_customer"."prcu_cust_part_num",
"contract_details"."cond_level1_amt",
"sales_history"."sah_year"
FROM (((("sisl_data05"."dbo"."products" "products"
LEFT OUTER JOIN "sisl_data05"."dbo"."prod_warehouse" "prod_warehouse"
ON ("products"."pr_prod_id"="prod_warehouse"."pw_prod_id")
AND ("products"."pr_prodline_id"="prod_warehouse"."pw_prodline_id"))
LEFT OUTER JOIN "sisl_data05"."dbo"."product_lookup" "product_lookup"
ON ("products"."pr_prod_id"="product_lookup"."prlkp_prod_id")
AND ("products"."pr_prodline_id"="product_lookup"."prlkp_prodline_id"))
LEFT OUTER JOIN "sisl_data05"."dbo"."prod_customer" "prod_customer"
ON ("products"."pr_prod_id"="prod_customer"."prcu_prod_id")
AND ("products"."pr_prodline_id"="prod_customer"."prcu_prodline_id"))
LEFT OUTER JOIN "sisl_data05"."dbo"."contract_details" "contract_details"
ON "prod_warehouse"."pw_prod_id"="contract_details"."cond_prod_id")
LEFT OUTER JOIN "sisl_data05"."dbo"."sales_history" "sales_history"
ON (("prod_warehouse"."pw_whs_id"="sales_history"."sah_sortkey1")
AND ("prod_warehouse"."pw_prod_id"="sales_history"."sah_sortkey2"))
AND ("prod_warehouse"."pw_prodline_id"="sales_history"."sah_sortkey3")
WHERE
"prod_warehouse"."pw_whs_id"='20123'
AND ("prod_warehouse"."pw_onhand_qty"<>0
OR "prod_warehouse"."pw_bin_location1"<>' '
OR "prod_warehouse"."pw_max_onhand_qty">0)
AND "sales_history"."sah_year"=2014
ORDER BY "prod_warehouse"."pw_bin_location1", "prod_warehouse"."pw_prod_id"Try this:
SELECT
prod_warehouse.pw_whs_id,
prod_warehouse.pw_prodline_id,
prod_warehouse.pw_prod_id,
prod_warehouse.pw_bin_location1,
prod_warehouse.pw_min_onhand_qty,
prod_warehouse.pw_max_onhand_qty,
prod_warehouse.pw_onhand_qty,
product_lookup.prlkp_lang1_1_desc,
prod_customer.prcu_cust_part_num,
contract_details.cond_level1_amt,
sales_history.sah_year
FROM sisl_data05.dbo.products products
LEFT OUTER JOIN sisl_data05.dbo.prod_warehouse prod_warehouse
ON products.pr_prod_id=prod_warehouse.pw_prod_id
AND products.pr_prodline_id=prod_warehouse.pw_prodline_id
LEFT OUTER JOIN sisl_data05.dbo.product_lookup product_lookup
ON products.pr_prod_id=product_lookup.prlkp_prod_id)
AND products.pr_prodline_id=product_lookup.prlkp_prodline_id
LEFT OUTER JOIN sisl_data05.dbo.prod_customer prod_customer
ON products.pr_prod_id=prod_customer.prcu_prod_id
AND products.pr_prodline_id=prod_customer.prcu_prodline_id
LEFT OUTER JOIN sisl_data05.dbo.contract_details contract_details
ON prod_warehouse.pw_prod_id=contract_details.cond_prod_id
LEFT OUTER JOIN sisl_data05.dbo.sales_history sales_history
ON prod_warehouse.pw_whs_id=sales_history.sah_sortkey1
AND prod_warehouse.pw_prod_id=sales_history.sah_sortkey2
AND prod_warehouse.pw_prodline_id=sales_history.sah_sortkey3
AND sales_history.sah_year = 2014
WHERE prod_warehouse.pw_whs_id='20123'
AND (prod_warehouse.pw_onhand_qty<>0
OR prod_warehouse.pw_bin_location1<>' '
OR prod_warehouse.pw_max_onhand_qty>0)
Take a look at what I've done with the last line of the last join. The issue is that when you left join to a table and you use that table in the Where clause, you've basically turned your you left outer join into an inner join because the record has to be there in order to get the value in the filter. By moving the filter into the join, you'll still get the rest of the data when there is no corresponding record.
NOTE: Crystal adds all sorts of "extra" stuff like quotes and parentheses that you don't need and which I have removed to make the query easier to read.
-Dell -
Need to adjust SQL query for left outer join in Crystal Reports 2008.
I need to change this SQL 2005 query.....
SELECT omnicell_anl.DeviceIDsLastMetricTable.member_id, omnicell_anl.DeviceIDsLastMetricTable.[Device Name],
omnicell_anl.DeviceIDsLastMetricTable.Account, omnicell_anl.labeledLastMetrics.PROPERTY_NAME,
omnicell_anl.labeledLastMetrics.latest_monitor_value
FROM omnicell_anl.DeviceIDsLastMetricTable LEFT OUTER JOIN
omnicell_anl.labeledLastMetrics ON omnicell_anl.DeviceIDsLastMetricTable.member_id = omnicell_anl.labeledLastMetrics.member_id
WHERE
omnicell_anl.labeledLastMetrics.PROPERTY_NAME = ?MyProperty
To this query in Crystal Reports Report Writer:
SELECT omnicell_anl.DeviceIDsLastMetricTable.member_id, omnicell_anl.DeviceIDsLastMetricTable.[Device Name],
omnicell_anl.DeviceIDsLastMetricTable.Account, omnicell_anl.labeledLastMetrics.PROPERTY_NAME,
omnicell_anl.labeledLastMetrics.latest_monitor_value
FROM omnicell_anl.DeviceIDsLastMetricTable LEFT OUTER JOIN
omnicell_anl.labeledLastMetrics ON omnicell_anl.DeviceIDsLastMetricTable.member_id = omnicell_anl.labeledLastMetrics.member_id AND
omnicell_anl.labeledLastMetrics.PROPERTY_NAME = ?MyProperty
I can't seem to get the left outer join function of Crystal Reports to emulate the same SQL query in SQL 2005. Any ideas on how I can create this same query in Crystal 2008?
Thanks,
Dominic
Edited by: Dominic Carissimi on Oct 28, 2008 7:55 PM
Edited by: Dominic Carissimi on Oct 28, 2008 7:56 PMIf you want the list of values for command level parameter then you need to add another command like
select PropertyField from table
and delete the links between this command and the existing command.
Now go to field explorer and edit the command level parameter and make it as dynamic and add the property field from newly added command.
Hope this helps!
Raghavendra -
Not using Index when SDO_RELATE in Spatial Query is used in LEFT OUTER JOIN
I want to know for every City (Point geometry) in which Municipality (Polygon geometry) it is.
Some cities will not be covered by any municipality (as there is no data for it), so its municipality name should be blank in the result
We have 4942 cities (point geometries)
and 500 municipalities (polygon geometry)
SELECT T1.NAME as City, T2.NAME as Municipality
FROM CITY T1
LEFT OUTER JOIN MUNICIPALITY T2 ON SDO_RELATE(T1.GEOM, T2.GEOM, 'MASK=ANYINTERACT') = 'TRUE'The explain plan for this query is:
SELECT STATEMENT
FILTER
Filter Predicates
MDSYS.SDO_RTREE_RELATE(T1.GEOM, T2.GEOM, 'mask=ANYINTERACT querytype=window ') = 'TRUE'
MERGE JOIN
TABLE ACCESS CITY FULL 11
BUFFER SORT 100605
TABLE ACCESS MUNICIPALITY FULL 20So the cost is in the BUFFER (whatever that is), it takes +2000 seconds to run this, it is not using the spatial index.
And we are not getting all rows, but only the ones interacting with a municipality, e.g. 2436 rows.
But I want all rows, including the ones not interacting with any Municipality.
When we want only those cities that actually are in a municipality, I use a different query and it will use the index.
SELECT T1.NAME as City, T2.NAME as Municipality
FROM CITY T1, MUNICIPALITY T2
WHERE SDO_RELATE(T1.GEOM, T2.GEOM, 'MASK=ANYINTERACT') = 'TRUE'I get (only) 2436 rows (as expected) in 5 seconds (it is fast) and the explain plan shows it is using the spatial index.
But in this case, I am not getting any cities not inside any municipality (of course)
SELECT STATEMENT
NESTED LOOPS
TABLE ACCESS MUNICIPALITY FULL 22
TABLE ACCESS CITY BY INDEX ROWID 22
DOMAIN INDEX CITY_SDX 0
Access Predicates
MDSYS.SDO_RTREE_RELATE(T1.GEOM, T2.GEOM, 'mask=ANYINTERACT querytype=window ') = 'TRUE'I always thought a LEFT OUTER JOIN would return all rows from the Table, whatever happens in the next,
but it seems the query has been rewritten so that it is now using a Filter Predicate in the end, which filters those geometries having no interaction.
As an example I also do thing alphanumerically, I do get 4942 rows, including the ones which have no Municipality name.
In this case the names must match, so its only for testing if the LEFT OUTER JOIN returns stuff correctly, which it does in this case.
SELECT T1.NAME as City, T2.NAME as Municipality
FROM CITY T1
LEFT OUTER JOIN MUNICIPALITY T2 ON T1.NAME = T2.NAMEIs this an Oracle Spatial bug, e.g. not return 4942 rows, but only 2436 rows on the first query?
Note all tests performed on Oracle 11g R2 (11.2.0.1.0)Patrick,
Even so, your geoms in the relate were the wrong way around.
Also, I don't recall you saying (or showing) that you wanted the municipality geometry returned. Still,
no matter, easy to do.
Here are some additional suggestions. I don't have your data so I have had to use some of my own.
set serveroutput on timing on autotrace on
SELECT T1.SPECIES as City,
(SELECT T2.ADMIN_NAME FROM AUSTRALIAN_STATES T2 WHERE SDO_ANYINTERACT(T2.GEOM, SDO_GEOM.SDO_BUFFER(T1.GEOM,10000,0.5,'UNIT=M')) = 'TRUE') as Municipality,
(SELECT T2.GEOM FROM AUSTRALIAN_STATES T2 WHERE SDO_ANYINTERACT(T2.GEOM, SDO_GEOM.SDO_BUFFER(T1.GEOM,10000,0.5,'UNIT=M')) = 'TRUE') as geom
FROM GUTDATA T1;
762 rows selected
Elapsed: 00:00:21.656
Plan hash value: 2160035213
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 762 | 49530 | 5 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| AUSTRALIAN_STATES | 1 | 115 | 0 (0)| 00:00:01 |
|* 2 | DOMAIN INDEX | AUSTRALIAN_STATES_GEOM_SPX | | | 0 (0)| 00:00:01 |
| 3 | TABLE ACCESS BY INDEX ROWID| AUSTRALIAN_STATES | 1 | 115 | 0 (0)| 00:00:01 |
|* 4 | DOMAIN INDEX | AUSTRALIAN_STATES_GEOM_SPX | | | 0 (0)| 00:00:01 |
| 5 | TABLE ACCESS FULL | GUTDATA | 762 | 49530 | 5 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("MDSYS"."SDO_ANYINTERACT"("T2"."GEOM","SDO_GEOM"."SDO_BUFFER"(:B1,10000,0.5,'UNIT=M'))='TRUE')
4 - access("MDSYS"."SDO_ANYINTERACT"("T2"."GEOM","SDO_GEOM"."SDO_BUFFER"(:B1,10000,0.5,'UNIT=M'))='TRUE')
Statistics
7 user calls
24576 physical read total bytes
0 physical write total bytes
0 spare statistic 3
0 commit cleanout failures: cannot pin
0 TBS Extension: bytes extended
0 total number of times SMON posted
0 SMON posted for undo segment recovery
0 SMON posted for dropping temp segment
0 segment prealloc tasksThe above can look messy as you add more (SELECT ...) attributes, but is is fast (though can't use in Materialized Views).
/* The set of all cities not in municipalities */
SELECT T1.SPECIES as City,
cast(null as varchar2(42)) as municipality,
cast(null as sdo_geometry) as geom
FROM GUTDATA T1
WHERE NOT EXISTS (SELECT 1
FROM AUSTRALIAN_STATES T2
WHERE SDO_ANYINTERACT(T2.GEOM, SDO_GEOM.SDO_BUFFER(T1.GEOM,10000,0.5,'UNIT=M')) = 'TRUE')
UNION ALL
/* The set of all cities in municipalities */
SELECT T1.SPECIES as City,
T2.ADMIN_NAME as Municipality,
T2.GEOM as geom
FROM GUTDATA T1
INNER JOIN
AUSTRALIAN_STATES T2 ON (SDO_ANYINTERACT(T2.GEOM, SDO_GEOM.SDO_BUFFER(T1.GEOM,10000,0.5,'UNIT=M')) = 'TRUE');
762 rows selected
Elapsed: 00:00:59.953
Plan hash value: 2854682795
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 99 | 13450 | 38 (87)| 00:00:01 |
| 1 | UNION-ALL | | | | | |
|* 2 | FILTER | | | | | |
| 3 | TABLE ACCESS FULL| GUTDATA | 762 | 49530 | 5 (0)| 00:00:01 |
|* 4 | DOMAIN INDEX | AUSTRALIAN_STATES_GEOM_SPX | | | 0 (0)| 00:00:01 |
| 5 | NESTED LOOPS | | 61 | 10980 | 33 (0)| 00:00:01 |
| 6 | TABLE ACCESS FULL| AUSTRALIAN_STATES | 8 | 920 | 3 (0)| 00:00:01 |
|* 7 | TABLE ACCESS FULL| GUTDATA | 8 | 520 | 4 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - filter( NOT EXISTS (SELECT 0 FROM "AUSTRALIAN_STATES" "T2" WHERE "MDSYS"."SDO_ANYINTERACT"("T2"."GEOM","SDO_GEOM"."SDO_BUFFER"(:B1,10000,0.5,'UNIT=M'))='TRUE'))
4 - access("MDSYS"."SDO_ANYINTERACT"("T2"."GEOM","SDO_GEOM"."SDO_BUFFER"(:B1,10000,0.5,'UNIT=M'))='TRUE')
7 - filter("MDSYS"."SDO_ANYINTERACT"("T2"."GEOM","SDO_GEOM"."SDO_BUFFER"("T1"."GEOM",10000,0.5,'UNIT=M'))='TRUE')
Statistics
7 user calls
131072 physical read total bytes
0 physical write total bytes
0 spare statistic 3
0 commit cleanout failures: cannot pin
0 TBS Extension: bytes extended
0 total number of times SMON posted
0 SMON posted for undo segment recovery
0 SMON posted for dropping temp segment
0 segment prealloc tasksMuch slower but Materialized View friendly.
This one is a bit more "natural" but still slower than the first.
set serveroutput on timing on autotrace on
/* The set of all cities in municipalities */
WITH municipal_cities As (
SELECT T1.ID as City,
T2.ADMIN_NAME as Municipality,
T2.GEOM as geom
FROM GUTDATA T1
INNER JOIN
AUSTRALIAN_STATES T2 ON (SDO_ANYINTERACT(T2.GEOM, SDO_GEOM.SDO_BUFFER(T1.GEOM,10000,0.5,'UNIT=M')) = 'TRUE')
SELECT T1.ID as City,
T2.Municipality as Municipality,
T2.GEOM as geom
FROM GUTDATA T1
LEFT OUTER JOIN
municipal_cities T2
ON (T2.CITY = T1.ID);
762 rows selected
Elapsed: 00:00:50.228
Plan hash value: 745978991
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 762 | 44196 | 36 (3)| 00:00:01 |
|* 1 | HASH JOIN RIGHT OUTER| | 762 | 44196 | 36 (3)| 00:00:01 |
| 2 | VIEW | | 61 | 3294 | 33 (0)| 00:00:01 |
| 3 | NESTED LOOPS | | 61 | 10980 | 33 (0)| 00:00:01 |
| 4 | TABLE ACCESS FULL | AUSTRALIAN_STATES | 8 | 920 | 3 (0)| 00:00:01 |
|* 5 | TABLE ACCESS FULL | GUTDATA | 8 | 520 | 4 (0)| 00:00:01 |
| 6 | INDEX FAST FULL SCAN| GUTDATA_ID_PK | 762 | 3048 | 2 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - access("T2"."CITY"(+)="T1"."ID")
5 - filter("MDSYS"."SDO_ANYINTERACT"("T2"."GEOM","SDO_GEOM"."SDO_BUFFER"("T1"."GEOM",10000,0.5,'UNIT=M'))='TRUE')
Statistics
7 user calls
49152 physical read total bytes
0 physical write total bytes
0 spare statistic 3
0 commit cleanout failures: cannot pin
0 TBS Extension: bytes extended
0 total number of times SMON posted
0 SMON posted for undo segment recovery
0 SMON posted for dropping temp segment
0 segment prealloc tasksFinally, the Pièce de résistance: trick the LEFT OUTER JOIN operator...
set serveroutput on timing on autotrace on
SELECT T1.SPECIES as City,
T2.ADMIN_NAME as Municipality,
T2.GEOM as geom
FROM GUTDATA T1
LEFT OUTER JOIN
AUSTRALIAN_STATES T2
ON (t2.admin_name = to_char(t1.ID) OR
SDO_ANYINTERACT(T2.GEOM, SDO_GEOM.SDO_BUFFER(T1.GEOM,10000,0.5,'UNIT=M')) = 'TRUE');
762 rows selected
Elapsed: 00:00:50.273
Plan hash value: 158854308
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 762 | 92964 | 2294 (1)| 00:00:28 |
| 1 | NESTED LOOPS OUTER | | 762 | 92964 | 2294 (1)| 00:00:28 |
| 2 | TABLE ACCESS FULL | GUTDATA | 762 | 49530 | 5 (0)| 00:00:01 |
| 3 | VIEW | | 1 | 57 | 3 (0)| 00:00:01 |
|* 4 | TABLE ACCESS FULL| AUSTRALIAN_STATES | 1 | 115 | 3 (0)| 00:00:01 |
Predicate Information (identified by operation id):
4 - filter("T2"."ADMIN_NAME"=TO_CHAR("T1"."ID") OR
"MDSYS"."SDO_ANYINTERACT"("T2"."GEOM","SDO_GEOM"."SDO_BUFFER"("T1"."GEOM",10000,0.5,'UNIT=M'))='TRUE')
Statistics
7 user calls
0 physical read total bytes
0 physical write total bytes
0 spare statistic 3
0 commit cleanout failures: cannot pin
0 TBS Extension: bytes extended
0 total number of times SMON posted
0 SMON posted for undo segment recovery
0 SMON posted for dropping temp segment
0 segment prealloc tasksTry these combinations to see what works for you.
Interestingly, for me, the following returns absolutely nothing.
SELECT T1.SPECIES as City,
T2.ADMIN_NAME as Municipality
FROM GUTDATA T1
LEFT OUTER JOIN
AUSTRALIAN_STATES T2
ON (SDO_ANYINTERACT(T2.GEOM, SDO_GEOM.SDO_BUFFER(T1.GEOM,10000,0.5,'UNIT=M')) = 'TRUE')
MINUS
SELECT T1.SPECIES as City,
T2.ADMIN_NAME as Municipality
FROM GUTDATA T1
LEFT OUTER JOIN
AUSTRALIAN_STATES T2
ON (t2.admin_name = to_char(t1.ID) OR
SDO_ANYINTERACT(T2.GEOM, SDO_GEOM.SDO_BUFFER(T1.GEOM,10000,0.5,'UNIT=M')) = 'TRUE');(I leave it to you to see if you can see why as the LEFT OUTER JOIN seems to be working correctly for me but I am not going to dedicate time to detailed checking of results.)
Note all tests performed on Oracle 11g R2 (11.2.0.1.0)
If you get the answer you want: mark the post as answered to assign points.
regards
Simon
Maybe you are looking for
-
How to positively get rid of AVG Secure search
I have tried many of the method suggested by user but AVG Secure Search is unaffected or goes away but keeps coming back. I don't understand how it only seems to affect people running Firefox and why Firefox seems to rely completely on forums and sug
-
Judder Effect from 3D Camera Renders
I have a 10 second camera pan (90 degree rotation) of a room. It has been rendered out from 3ds max. Each image looks great. When I put it together in AfterEffects, and render it out, I am getting a Judder effect (a vibration as I go across the pa
-
How do I create new folders in my inbos to drag mail into?
-
Restarting loop after update to 10.5.7!
Hey Guys, I have a serious problem with OSX after updating to 10.5.7! I updated through Software Update and the macbook restarted. After that it went into a restarting loop. It boots-up, the logo and moving circle appears, and then it restarts. I tri
-
Display message when record is save in table
Hello, How can i display message as "Record Save" when record successfully save into table. I have created a form and take one save button, when values fill up in the textboxes and SAVE button pressed record is successfully inserted in the table then