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.
Similar Messages
-
LEFT OUTER JOIN, Problem in POST-QUERY TRIGGER
Hi,
Please guide for the following
I wrote below query in POST-QUERY Trigger of a TABULAR DATA BLOCK, having only one text item, called INVENTORY_ITEM
select c.cat||' '||s.subcat||' '||l1.lvl1 ITEM INTO :DATABLOCK.INVENTORY_ITEM
from itemcat c
LEFT OUTER JOIN itemsubcat s on (c.catid = s.catid)
LEFT OUTER JOIN lvl1 l1 on (s.subcatid = l1.subcatid)
When I compile the module an error is generated
*" Encountered the symbol 'LEFT' when expecting one of the following ,; for group having intersect minus order start union where connect ".*
Above query is working fine in ORACLE SQL DEVELOPER .
Any solution please.
Regards,Difference
-
Left Outer Join Problem for Multiple Condition
Hi This is the code and I want to return the vlaues evens if it is not ther so my Sysntax is not right for that can you plz help me
SELECT ap.descripcion AS Production_Description,
conceptes.descripcion AS Concepts_Description ,
um.Nomenclatura AS Unit_Measure ,
-- real_daily_detail.FechaProduccion AS Production_Date ,
period.Codigo as June,
period.anio AS YEAR_08 ,
rmd.Valor AS Values_Monthly,
budgetd.Valor as Budget
FROM sgr_area_produccion ap ,
sgr_conceptos conceptes ,
SGR_Unidad_Medida um ,
SGR_Unidad_Produccion up ,
SGR_Unidad_Area_Produccion uap ,
SGR_Real_Mensual_Detalle rmd ,
SGR_Periodo period ,
SGR_Real_Mensual rm ,
SGR_Presupuesto budget ,
SGR_Presupuesto_Detalle budgetd
where uap.ID_Unidad_Produccion = up.ID_Unidad_Produccion (+)
and uap.ID_Area_Produccion = ap.ID_Area_Produccion (+)
and rm.ID_Area_Produccion = uap.ID_Area_Produccion (+)
and rm.ID_Unidad_Produccion = uap.ID_Unidad_Produccion (+)
and rmd.ID_Unidad_Produccion = rm.ID_Unidad_Produccion (+)
and rmd.ID_Area_Produccion = rm.ID_Area_Produccion (+)
and rmd.ID_Periodo = rm.ID_Periodo (+)
and period.ID_Periodo = rm.ID_Periodo (+)
and conceptes.ID_Concepto = rmd.ID_Concepto (+)
and budget.ID_Unidad_Produccion = uap.ID_Unidad_Produccion(+)
and budget.ID_Area_Produccion = uap.ID_Area_Produccion (+)
and budget.ID_Unidad_Produccion = budgetd.ID_Unidad_Produccion
and budget.ID_Area_Produccion = budgetd.ID_Area_Produccion (+)
and budget.ID_Periodo = budgetd.ID_Periodo (+)
and period.ID_Periodo = budget.ID_Periodo (+)
and period.Codigo = 'JUNIO-08'
and conceptes.ID_Concepto = budgetd.ID_Concepto (+)
and daily.ID_Area_Produccion = uap.ID_Area_Produccion (+)
and daily.ID_Unidad_Produccion = uap.ID_Unidad_Produccion (+)
and dailyd.ID_Unidad_Produccion = daily.ID_Unidad_Produccion(+)
and dailyd.ID_Area_Produccion = daily.ID_Area_Produccion (+)
and period.ID_Periodo = daily.ID_Periodo (+)
and conceptes.ID_Concepto = dailyd.ID_Concepto (+)
and um.ID_Unidad_Medida = conceptes .ID_Unidad_Medida (+)Oracle old outer join syntax had more restrictions than more recent ANSI outer join syntax. I do'nt want to emulate compiler and go through your code to spot any possible problems, even more if you cannot say also the exact error or exact problem what you get.
And bear in mind that for outer joins THERE IS DIFFERENCE [url http://www.gplivna.eu/papers/sql_join_types.htm#p6.4]between join conditions and predicates in where clause.
Gints Plivna
http://www.gplivna.eu -
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. -
Problem with XMLTABLE and LEFT OUTER JOIN
Hi all.
I have one problem with XMLTABLE and LEFT OUTER JOIN, in 11g it returns correct result but in 10g it doesn't, it is trated as INNER JOIN.
SELECT * FROM v$version;
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
"CORE 11.2.0.1.0 Production"
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
--test for 11g
CREATE TABLE XML_TEST(
ID NUMBER(2,0),
XML XMLTYPE
INSERT INTO XML_TEST
VALUES
1,
XMLTYPE
<msg>
<data>
<fields>
<id>g1</id>
<dat>data1</dat>
</fields>
</data>
</msg>
INSERT INTO XML_TEST
VALUES
2,
XMLTYPE
<msg>
<data>
<fields>
<id>g2</id>
<dat>data2</dat>
</fields>
</data>
</msg>
INSERT INTO XML_TEST
VALUES
3,
XMLTYPE
<msg>
<data>
<fields>
<id>g3</id>
<dat>data3</dat>
</fields>
<fields>
<id>g4</id>
<dat>data4</dat>
</fields>
<fields>
<dat>data5</dat>
</fields>
</data>
</msg>
SELECT
t.id,
x.dat,
y.seqno,
y.id_real
FROM
xml_test t,
XMLTABLE
'/msg/data/fields'
passing t.xml
columns
dat VARCHAR2(10) path 'dat',
id XMLTYPE path 'id'
)x LEFT OUTER JOIN
XMLTABLE
'id'
passing x.id
columns
seqno FOR ORDINALITY,
id_real VARCHAR2(30) PATH '.'
)y ON 1=1
ID DAT SEQNO ID_REAL
1 data1 1 g1
2 data2 1 g2
3 data3 1 g3
3 data4 1 g4
3 data5 Here's everything fine, now the problem:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bi
PL/SQL Release 10.2.0.1.0 - Production
"CORE 10.2.0.1.0 Production"
TNS for HPUX: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
--exactly the same environment as 11g (tables and rows)
SELECT
t.id,
x.dat,
y.seqno,
y.id_real
FROM
xml_test t,
XMLTABLE
'/msg/data/fields'
passing t.xml
columns
dat VARCHAR2(10) path 'dat',
id XMLTYPE path 'id'
)x LEFT OUTER JOIN
XMLTABLE
'id'
passing x.id
columns
seqno FOR ORDINALITY,
id_real VARCHAR2(30) PATH '.'
)y ON 1=1
ID DAT SEQNO ID_REAL
1 data1 1 g1
2 data2 1 g2
3 data3 1 g3
3 data4 1 g4As you can see in 10g I don't have the last row, it seems that Oracle 10g doesn't recognize the LEFT OUTER JOIN.
Is this a bug?, Metalink says that sometimes we can have an ORA-0600 but in this case there is no error returned, just incorrect results.
Please help.
Regards.Hi A_Non.
Thanks a lot, I tried with this:
SELECT
t.id,
x.dat,
y.seqno,
y.id_real
FROM
xml_test t,
XMLTABLE
'/msg/data/fields'
passing t.xml
columns
dat VARCHAR2(10) path 'dat',
id XMLTYPE path 'id'
)x,
XMLTABLE
'id'
passing x.id
columns
seqno FOR ORDINALITY,
id_real VARCHAR2(30) PATH '.'
)(+) y ;And is giving me the complete output.
Thanks again.
Regards. -
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 -
Left Outer Join with more than two tables in both CR 8.5 and XIR2
I am trying to create a report and I have tried two versions of Crystal but I ultimately need the report in CR8.5 for compatibility with the client's system. I think I am starting to figure out what might be wrong and it might be my understanding of SQL, but I can't see why someone hasn't needed this in the past. Ultimately I want to see all projects and any journal entry that might be posted for that project.
Database is MySQL 5.0.38 and using MySQL ODBC driver 3.51.19.
Project header table information will be populated. Each line item on a journal entry can be tagged with the project ID. But for me to pull the journal entry date I need also to link to a third table for the journal entry header info.
I want to see all projects, whether a journal entry has been posted or not.
So the links are like this
ProjectHeader --->Left Outer Join ---> JELines ---> Inner Join ---> JEHeader
I think in this scenerio Crystal is treating the LOJ as an IJ.
I created two brand new reports today, one in CR8.5 and one in CR XIR2. Once I edited the automatic CR8.5 SQL statement (which I have been doing for years, usually without problem), they both ran properly. I linked customers to their invoices. Customers without invoices showed properly. But then I linked the invoices to the payments of the invoices and immediately lost customers without orders in both reports.
So apparently only two tables are allowed in Outer Joins. Does this make sense? I checked out the w3schools tutorial on SQL and it doesn't mention this limitation and I can't find anywhere else that it specifically indicates this but all samples of code I have seen only show two tables. I just thought for presentation as a sample that was easiest to understand and we could expand as necessary.
If this is correct, how does one go about accounting for this kind of thing? One solution that goes through my mind is creating a view at the database level for the link between journal entry lines and journal entry headers. Would this be a good solution under normal circumstances?
A second option that I had to implement because of timelines, is to use a subreport linked to the main report through the project ID to pull the information for the journal entries and just pass the totals I need to the main report through a shared variable.
These aren't normal circumstances because I don't have access to the database so I can't create the view. I have come across this concept several times and I have been able to use subreports to solve it but I am trying to find a better solution for the future as sometimes subreports can be slow. So are there any alternatives I have not considered here?
TIA rasincSo after some more work and another post. I was able to get this to work.
Items disappear when linking to another table
My issues were two fold. I was selecting on the tables on the right-side of the original Inner Join. However, I was checking for Nulls. This apparently is correct but you must check for the Nulls first eg. (IsNull (JEHeader.Field1) OR JEHeader.Field1 <= 100). I had my original statement reversed checking for <= 100 before checking for Nulls.
I also did not set all links to be Left Outer Join. I had the Inner Join. I actually have about 6 tables in this report so all the links need to be set Outer Join. So this now seems to be corrected.
Thanks -
Left outer join 3 tables with where-statement
Hi folks,
I hope you can understand (and maybe solve) my problem.
Generally I try to left outer join three tables. The third table is used for a WHERE-statement.
The three table structures are the following:
table 1 (user)
user1 | key
table 2 (detail)
key | ID
table 3 (header)
ID | user2
...and I want to achieve the following structure (as example filled with data):
user | key | ID
|-----|----
xy | a | 001
xy | b | #
z | b | #
The clue ist the usage of the third table. I need the table to set user1 and user2 equal (WHERE) but there are two problems:
1) Obviously I can't left outer join two tables with each other. In this case I already used the 'key' of table 1 to join it with the 'key' of table 2. So I can't left outer join the 'ID' of table 2 with the 'ID' of table 3. Error message that I can only left outer join a table once. Any proposals?
2) I have to include a WHERE to equal user1 with user2. But I am not allowed to use the user2 from table 3 because of the left outer join.
I tried this coding:
SELECT auser1 akey b~id INTO TABLE itab FROM ( table1 AS a
LEFT OUTER JOIN table2 AS b ON akey = bkey )
LEFT OUTER JOIN table3 AS c ON bID = cID )
WHERE auser1 = cuser2.
I would really appreciate your help.
Regards
MrclSpdlIF you want to join a DB table with an internal table, you need to use the 'FOR ALL ENTRIES' statement.
select dbfields
into table itab2
from dbtab
for all entries in itab
where dbfield1 = itab-field1.
This will get you a second internal table with all the corresponding data for the first selection. You can then join them with a loop through the first table and a read table on the second table (for 1 - 1 relation) or a nested loop statement on both tables (for 1 - N relation). Make itab a hashed table when using read table with key, use a sorted table if you need to loop without key access.
Regards,
Freek -
Filter on "---" in Left Outer Join Query
Hi guys,
very basic question but I have not found an answer, yet. I built an left outer join MDO query and need to select all those dataset that did not find a "partner", that is fields are set to "---". However, I do not manage to filter on '---', NULL...
When using SQL, it appears to be a String "---" but in MDO???Hey guys, found out that IS NULL needs to be used in query. Anyway, it appears to cause problems somewhere else.
I placed an IS NULL filter expression inside a join query but query did not return any results when called in by transaction. After removing this line, both NULL and NOT NULL data were returned. When used in test mode, IS NULL was working fine... -
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 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 -
Hi Experts,
I am facing a problem with left outer join query. Am using one standard table and ztable for this join. My problem is values are not extracted from the Ztable.
Query:
SELECT b~lifnr b~belnr b~gjahr b~xblnr b~shkzg b~blart b~zfbdt b~budat b~wrbtr
b~wskto b~zlspr s~EXTRACT_STATUS s~maturity_date FROM bsik AS b
LEFT OUTER JOIN zprm_rvne_sapdoc AS s
ON s~belnr EQ b~belnr
AND s~gjahr EQ b~gjahr
INTO CORRESPONDING FIELDS OF TABLE it_join
WHERE b~zlsch = p_zlsch
AND b~xblnr IN so_invno
ORDER BY b~lifnr b~xblnr.
I have all entries of BSIK table in Ztable with extract status as Y but this query is not fetching extract status and maturity date of ztable so it is blank in the internal table.
Need solution.
Regards
Sridevi SHi,
see the sample wiki for writing the Left outer join
http://wiki.sdn.sap.com/wiki/display/Snippets/EmployeeInfotype0000to9999ChangeHistory
Specifying Two or More Database Tables as a Left Outer Join
The left outer join, on the other hand, reads lines from the left-hand database table or join even if there is no corresponding line in the right-hand table.
SELECT...
FROM <tab> LEFT [OUTER] JOIN <dbtab> [AS <alias>] ON <cond>
<options>
<tab> and <dbtab> are subject to the same rules and conditions as in an inner join. The OUTER addition is optional. The tables are linked in the same way as the inner join with the one exception that all lines selected from <tab> are included in the final selection. If <dbtab> does not contain any lines that meet the condition <cond>, the system includes a single line in the selection whose columns from <dbtab> are filled with null values.
In the left outer join, more restrictions apply to the condition <cond> than in the inner join. In addition to the above restrictions:
EQ or = is the only permitted relational operator.
There must be at least one comparison between columns from <tab> and <dbtab>.
The WHERE clause may not contain any comparisons with columns from <dbtab>. All comparisons using columns from <dbtab> must appear in the condition <cond>.
If we have two tables named stud1,stud2 with the following data
Stud1: id Name stud2: id Name
1 xxx 1 aaa
2 yyy 2 bbb
3 zzz 4 ccc
4 www 6 ddd
When we use Left Outer Join we get the output as:
1 aaa
2 bbb
3 <Null>
4 ccc
When we use Right Outer Join we get the output as:
1 aaa
2 bbb
4 ccc
<Null> ddd
When we use Full Outer Join we get the output as:
1 aaa
2 bbb
3 <Null>
4 ccc
<Null> ddd
Prabhudas -
I need to join these two tables and have a problem becuase it's difficult to join the tables with the keys.
Basically here is a sample of the data.
The only way I get the correct number of rows returned is with a left outer join on unit, asset_id and sequence_number.
COST
unit asset_id sequence_number
01 113317 0
01 113317 1
01 113317 1
ACQ_DETAIL
unit asset_idnbsp sequence_number vendor_id
01 113317 1 ABCConstruction
So with the left outer join you'd get
unit asset_idnbsp sequence_number vendor_id
01 113317 0
01 113317 1 ABCConstruction
01 113317 1 ABCConstruction
I need to join on sequence_number or else I get too many rows returned. Is there anyway I can keep the outer join (still joining on thows three keys) and have this returned.
unit asset_idnbsp sequence_number vendor_id
01 113317 0 ABCConstruction
01 113317 1 ABCConstruction
01 113317 1 ABCConstruction
Thanks all!!COST
unit asset_id seq_no
[pre]01 1137 0
[pre]01 1137 1
[pre]01 1137 1
ACQ_DET
[pre]unit asset_id seq_no vendor_id
[pre]01 1137 1 ABC
[pre]01 1137 3 XYZ
RETURNS
[pre]01 1137 ABC
[pre]01 1137 ABC
[pre]01 1137 ABC
THANKS!! -
Left Outer Joining multiple tables to one source table FAILS with VLD-1511
Hi all,
Is it me, or is OWB unable to handle left outer joining 1 source table to multiple other tables?
I want to load a fact table so I have 1 source table with measures. This table must be outer joined to some dimensions that have their FK in the fact table.
The SQL statement would look like this (and is perfectly valid):
select ...
from input, dim1, dim2
where input.c1 = dim1.c1(+)
and input.c2 = dim2.c2(+);
I put the where clause in the joiner operator and validate, but that gives me message VLD-1511: A table may be outer joined to at most one other table.
Even splitting this up into one outer join per joiner still gives this message.
A search and look around on the forum and on metalink shows there are related issues (like bug 3334035). Seemingly creating a view is the work-around to use.....? (ie downgrading owb to a simple gui tool) }-;
Have other people experienced this problem of not being able to outer join one input table to multiple other tables?
Thanks,
EdI have had some feedback from Oracle. It turns out this has to do with 2 issues. Below I have pasted the text that Support gave me:
<---------- START QUOTE ---------->
RESEARCH
=========
Bug 3437036 KEY LOOKUP DOES NOT DETECT ORA-1417 IN VALIDATE/GENERATE STEP
Unpublished Bug 4211684 FORWARD PORT OF BUG 3437036
shows:
Some more development has been completed when this bug is fixed in Paris.
The following are the details:
1. If the join condition contains a full outer join such as
tab1.c (+) = tab2.c (+) and tab2.c (+) = tab3.c
then the new validations implemented for this bug do not apply since
in OWB, full outer join triggers generation of joins in ANSI syntax.
ANSI syntax does not have the original problem the base bug of this
bug reported.
2. If the join condition does not contain any full outer join condition,
then the join is generated in Oracle join syntax, which is subject two
several restrictions. The fix to this bug check two of the restrictions.
3. The first restriction in Oracle syntax is that the outer join operator
"(+)" can only directly be attached to a column name. If you attach it
to an expression, such as the following:
(tab1.c + 1) (+) = tab2.c
Then there will be an ORA-936 error at the time of mapping deployment.
For this case, I have added a validation message VLD-1512 to error out
this situation.
4. The second restriction in Oracle syntax is that a table can only be
outer joined to exactly one other table.
For example, this is an invalid join in Oracle syntax:
tab1.c (+) = tab2.c and tab1.d (+) = tab3.d
because tab1 is left outer joined to tab2 and tab3.
But note that the following is still valid in Oracle syntax:
tab1.c (+) = tab2.c and tab1.d = tab3.d (+)
because tab1 is left outer joined to tab2 and right outer joined to tab3.
So this latter case does not violate the restriction that "same oj" to
more than 1 table is not allowed.
If same oj to more than 1 table is specified in a join condition,
VLD-1511 will be issued, and the map is made invalid.
<---------- END QUOTE ---------->
OWB does a partial validation, ie not all access paths are (can be) checked. A full check is only done by the database itself. So some scenarios (like checking whether multiple tables are outer joined the correct way) are not checked, and in this case are flagged with an error (even though it is actually a correct scenario).
Seemingly this was not flagged with an error in earlier versions of OWB, so beware, OWB behaviour may change when upgrading...
Alternative solutions are (1) using key lookups, (2) using a view with all outer joins in there, (3) using intermediate result tables between the joins.
Hope this info helps some people prevent spending too much time on a false error message,
Ed -
Left outer join in presentation layer
Could I do left outer join in presentation layer? I have 2 reports. They both have a common column - "Month". The first report have columns - "Month" and "Measure1" and the second report have columns - "Month" and "Measure2". I would like to put them together so the final report would have "Month", "Measure1" and "Measure2".
Thanks,
TedTed,
It is not clear to me, why you want to do an outer join. If the dimension Month is shared by both "Measure1" and "Measure2", then it will work without any problem (assuming the RPD is configured correctly).
An outer join comes into play if you need to preserve the dimension records. Let's assume you want to run an analysis like "Show me all months were there was no sales". In plain SQL you would to do a left-outer join between the Month dimension table and the sales fact table. If you want to know how this can be achieved in OBIEE you might want to have a look here [Outer join style report - OBIEE 10g|https://forums.oracle.com/forums/message.jspa?messageID=9805768#9805768]. This should be still valid for OBIEE 11g.
Best regards,
Peter
Maybe you are looking for
-
Power Point for the PC has a feature that allows you to highlight an object (a croped picture, chart, etc.) right click and Save it as a Picture in many formats (jpeg etc.). Does that feature exist in the Adobe Acrobat 8 Professional? If it does ---
-
Adcfgclone dbTier error in R12
Hi all, Installed Oracle home 10.2.0.3 converted it to 64 bit, enabled autoconfig...and trying to run adcfgclone it says RC-00126: Update inventory failed. The inventory pointed at location /xxxx/db/tech_st/10.2.0/oraInventory is not valid Raised by
-
I have a program that writes t
o a spreadsheet, however, i would like to write to a new file at the beginning of each new day, and i would like the filename to be provided from my program, where the filename would be equal to a short string concatenated by the date string. Please
-
Disater Recovery for exchange 2010 plan.
Hi All, Happy New year 2014 .... we have running with exchange 2010 R1 with DAG enabled. we have below mentioned setup in our exchange server. Main site. Active directory server ( Primary DC, additional DC in our main site) installed in Hyper V hos
-
Can the account owner block other users of the account from viewing usage information? If so, how can you do that?