Where clause in Joins
I have a selection screen like:
Table Field
EKKO EKORG
EKKO EKGRP
EKKO LIFNR
ESSR EBELN
ESSR EBELP
ESSR LBLNE
ESSR FRGZU
ESSR ERDAT
ESSR LOEKZ
Due to further complexities in the program i am joining 3 tables EKKO, EKPO and ESSR together. I can write the select stmt in 2 ways. I want to understand which one is better in terms of performance and is there exactly a rule here that i should follow before i write the where clause in this join.
SELECT aebeln bebelp alifnr aekorg aekgrp bpackno c~lblni
clblne cerdat cpackno cloekz cfrgsx cfrgkl c~frgzu
INTO TABLE gt_test
FROM ekko AS a INNER JOIN ekpo AS b
ON aebeln = bebeln
INNER JOIN essr AS c
ON aebeln = cebeln
AND bebeln = cebeln
AND bebelp = cebelp
WHERE a~lifnr IN so_lifnr
AND a~ekorg IN so_ekorg
AND a~ekgrp IN so_ekgrp
AND c~lblne IN so_lblne
AND c~ebeln IN so_ebeln
AND c~ebelp IN so_ebelp
AND c~erdat IN so_erdat.
SELECT aebeln bebelp alifnr aekorg aekgrp bpackno c~lblni
clblne cerdat cpackno cloekz cfrgsx cfrgkl c~frgzu
INTO TABLE gt_test
FROM ekko AS a INNER JOIN ekpo AS b
ON aebeln = bebeln
INNER JOIN essr AS c
ON aebeln = cebeln
AND bebeln = cebeln
AND bebelp = cebelp
WHERE a~ebeln IN so_ebeln
AND a~lifnr IN so_lifnr
AND a~ekorg IN so_ekorg
AND a~ekgrp IN so_ekgrp
AND b~ebelp IN so_ebelp
AND c~lblne IN so_lblne
AND c~erdat IN so_erdat.
AND c~erdat IN so_erdat.
Hi,
This part is not necessary:
... a~ebeln = c~ebeln ...
Modify:
AND c~ebeln IN so_ebeln
AND c~ebelp IN so_ebelp
by
AND a~ebeln IN so_ebeln
AND b~ebelp IN so_ebelp
The best option will be:
if not so_ebeln[] is initial.
select ... where a~ebeln IN so_ebeln ... (2nd select)
else.
select ... where a~lifnr IN so_lifnr ... (1st select)
endif.
Also, you can try only the 2nd select, because it has WHERE clause to ebeln and lifnr. Depending on your database, you can check (via ST04) if the right index is selected (eg. if you inform so_ebeln the database must do the selection using ebeln index. if you inform so_lifnr the database must do the selection using lifnr index, etc..)
Best regards,
Leandro Mengue
Similar Messages
-
HI all,
If i Have a select statement that needs two different tables
and a where clause with only 1 join and the rest of conditions dependent on only 1 table such as:
select .... from table a, table b
where a.col1 = b.col1
and b.col2 some condition
and b.col3 some condition;
is it better/optima for performancel for me to have the join right at the beginning of the where clause or after table b has been filtered out such as:
select ... from table a, table b
where b.col2 some condition
and b.col3 some condition
and a.col1 = b.col1Hi,
The order of conditions in a WHERE clause doesn't effect performance; the Cost-Based Optimizer will decide how to perform them.
The order can make a difference on how easy it is to understand and maintain the code. I find ANSI join syntax far better for this:
select ...
from table a
join table b on a.col1 = b.col1
where b.col2 <some condition>
and b.col3 <some condition>
; -
Using Parameters in SQL-Query not only in where clauses
Hi,
I try to use Publisher parameters in the SQL Query from a Data Set.
All of them have default values.
So far, this is no problem, unless I try to use such a parameter value as an ordinary attribute value:
>
select
case when (:pv_Group = 'no') then "DM15D_BETRIEBSTEIL"."BETR_TEIL"
else :pv_some_Text end as Betr_Teil,
case when (:pv_Group = 'no') then "DM15D_BETRIEBSTEIL"."SUVA_NR_FORM"
else :pv_some_Text end as Suva_Nr,
case when (:pv_Group = 'no') then "DM15K_RIS_FAKTEN_PRO_BTT_JHR"."RIS_VOLLBESCH"
else sum("DM15K_RIS_FAKTEN_PRO_BTT_JHR"."RIS_VOLLBESCH") end as Vollbesch
from "GDWH05"
where
"DM15D_BETRIEBSTEIL"."SUVA_NR_FORM" in (:pv_nim100)
fetch first 65001 rows ONLY
>
The parameters 'pv_Group' and 'pv_nim100' are working fine. (when or where clauses)
The parameter 'pv_some_Text' unfortunately not. (simple literals)
When I try to validate the above SQL, I get the following Error:
<font color="red">
java.io.IOException: prepare query failed[nQSError: 43113] Message returned from OBIS. [nQSError: 46033] Datatype: 25 is not supported.
</font>
After use a cast function:
>
else CAST(:pv_some_Text AS CHARACTER)
>
I get this ERROR:
<font color="red">
java.io.IOException: prepare query failed[nQSError: 43113] Message returned from OBIS. [nQSError: 19002] Incorrect use of parameters. The parameters used in CAST cannot be resolved without ambiguity.
</font>
We use OBIEE 11.1.1.6.4 on a Win64-System.
Thank's for any help.Hi Alex,
let's leave away any unnecessary details.
This is the SQL, inserted in the window 'Edit Data Set' of BIP Data Model:
>
select
'--1' as Betr_Teil,
'--2' as Suva_Nr,
sum("GDWH05"."DM15K_RIS_FAKTEN_PRO_BTT_JHR"."RIS_VOLLBESCH") as Vollbesch
from "GDWH05"
where
"DM15D_BETRIEBSTEIL"."SUVA_NR_FORM" in ('122-4.4')
fetch first 65001 rows ONLY
>
Everything is fine when I click OK, the script goes back to the metadata.
Let's try this script with bind values in ORACLE SQL Developer.
This SQL is the physical part, found in the OBIEE-Log (Log level 5), except the bind values. Therefore we find, in the where clause, the join. In the logical sql, we don't have to join, because it's handled in the Common Enterprise Information Model (CEIM)
>
with
sawith0 as
select
sum(t39617.ris_vollbesch) as c1
from
dm15d_betriebsteil t39455,
dm15k_ris_fakten_pro_btt_jhr t39617
where
t39455.id_betriebsteil = t39617.id_betriebsteil
and t39455.suva_nr_form = '122-4.4'
select
d1.c1 as c1,
d1.c2 as c2,
d1.c3 as c3
from
select
:pv_some_text as c1,
:pv_some_text as c2,
sum(d1.c1) as c3
from
sawith0 d1
d1
where
rownum <= 65001
>
This SQL works fine, even with bind values for 'pv_some_text'.
But, when using the following SQL in the BIP Data Model:
>
select
:pv_Text as Betr_Teil,
:pv_Text as Suva_Nr,
sum("GDWH05"."DM15K_RIS_FAKTEN_PRO_BTT_JHR"."RIS_VOLLBESCH") as Vollbesch
from "GDWH05"
where
"DM15D_BETRIEBSTEIL"."SUVA_NR_FORM" in ('122-4.4')
fetch first 65001 rows ONLY
>
The following ERROR occurs:
<font color="red">java.io.IOException: prepare query failed[nQSError: 43113] Message returned from OBIS. [nQSError: 46008] Internal error: File server\Query\Optimizer\ServiceInterfaceMgr\Utility\Src\SQOIUTypeVisitor.cpp, line 643.</font>
In my opinion, either I use a wrong syntax, or BIP has a problem with parsing the script.
Thank you for your most welcome help. -
Where clause with 3 tables?
hi all
can anyone check the following query for me and guide me can we join 3 tables with where clause?
SELECT ALL SLIP.NUM, SLIP.NAME, SLIP.NAT, SLIP.JOIN, SLIP.JOB, SLIP.GENDER,
SLIP.BANK, SLIP.ACCOUNT, SLIP.YEAR, SLIP1.NUM, SLIP1.BASIC, SLIP1.CODE,
SLIP1.HOUSE, SLIP1.TRANS, SLIP1.WATER, SLIP2.NUM, SLIP2.AMOUNT,
SLIP2.OTHER, SLIP2.DEDUCT, SLIP2.MONEY, SLIP2.TOTAL, SLIP2.NET
FROM SLIP, SLIP1, SLIP2
WHERE (SLIP.NUM = :p_num
AND SLIP.NAME = :p_name
AND SLIP.NAT = :p_nat
AND SLIP.JOIN = :p_join
AND SLIP.JOB = :p_job
AND SLIP.GENDER = :p_gender
AND SLIP.BANK = :p_bank
AND SLIP.ACCOUNT = :p_account
AND SLIP.YEAR = :p_year
AND SLIP1.NUM = :p_num1
AND SLIP1.BASIC = :p_basic
AND SLIP1.CODE = :p_code
AND SLIP1.HOUSE = :p_house
AND SLIP1.TRANS = :p_trans
AND SLIP1.WATER = :p_water
AND SLIP2.NUM = :p_num2
AND SLIP2.AMOUNT = :p_amount
AND SLIP2.OTHER = :p_other
AND SLIP2.DEDUCT = :p_deduct
AND SLIP2.MONEY = :p_money
AND SLIP2.TOTAL = :p_total
AND SLIP2.NET = :p_net)
AND (SLIP.NUM = SLIP1.NUM)
sarah
Edited by: SarahSarahSarah on Aug 16, 2009 8:38 AMI would guess, at a minimum, that you want to have a WHERE clause that joins SLIP2 to either SLIP or SLIP1. Since you know your data model, you'll have to tell us how SLIP2 relates to the other two tables.
If you really have tables named SLIP, SLIP1, and SLIP2, I would have some rather serious concerns about your data model. Having three tables that store different data but have virtually the same name would be rather concerning.
Justin -
How can I pass multiple condition in where clause with the join table?
Hi:
I need to collect several inputs at run time, and query the record according to the input.
How can I pass multiple conditions in where clause with the join table?
Thanks in advance for any help.
Regards,
TDIf you are using SQL-Plus or Reports you can use lexical parameters like:
SELECT * FROM emp &condition;
When you run the query it will ask for value of condition and you can enter what every you want. Here is a really fun query:
SELECT &columns FROM &tables &condition;
But if you are using Forms. Then you have to change the condition by SET_BLOCK_PROPERTY.
Best of luck! -
Outer Join with Where Clause in LTS
HI all,
I have a requirement like this in ANSI SQL:
select p1.product_id, p1.product_name, p2.product_group
from product p1 left outer join product_group p2 on p1.product_id = p2.product_id
and p2.product_group = 'NEW'
In Regular SQL:
select p1.product_id, p1.product_name, p2.product_group
from product p1, product_group p2
WHERE p1.product_id *= p2.product_id and p2.product_group = 'NEW'
In OBIEE, I am using a left outer join between these two in Logical table Source, and also, Gave
p2.product_group = 'NEW' in WHERE clause of LTS.
This doesn't seem to solve purpose.
Do you have any idea how to convert WHERE clause in physical query that OBIEE is generating to something like
product p1 left outer join product_group p2 on p1.product_id = p2.product_id AND p2.product_group = 'NEW'
I am using Version 10.1.3.4.1
Creating an Opaque view would be my last option though.Hello
I have read your post and the responses as well. and I understand that you have issues with the Outer Join with where Clause in LTS.
Try this solution which worked for me (using your example ) -
1. In the Physical Layer created a Complex join between PRODUCT and PRODUCT_GROUP tables and use this join relationship :
PRODUCT.PROD_ID = PRODUCT_GROUP.PROD_ID AND PRODUCT_GROUP.GROUP_NAME = 'MECHANICAL'
2. In the General Tab of PRODUCT table LTS add PRODUCT_GROUP table and select Join Type as Left Outer Join.
3. Check Consistency and make sure there are no errors .
when you run a request you should see the following query generated -
select distinct T26908.PROD_ID as c1,
T26908.PROD_NAME as c2,
T26912.GROUP_NAME as c3
from
PRODUCT T26908 left outer join PRODUCT_GROUP T26912 On T26908.PROD_ID = T26912.PROD_ID and T26912.GROUP_NAME = 'MECHANICAL'
order by c1, c2, c3
Hope this works for you. If it does please mark this response as 'Correct' .
Good Luck. -
WHERE clause creating a join for two or more tables
The CS3 Dreamweaver book says that the WHERE clause can
create a join for two or more tables. The join was created, but the
data is repeating. I have searched the web and this forum and have
not found the answer.
My Master page filters the recordset by Style No and when a
customer clicks on a particular style, it sends him to the Detail
page. All the records are showing from all tables on the detail
page from the Dynamic List, except they are showing multiple times
(ex. Size table has 4 sizes and Color table has 2 colors - my Size
Drop Down list is showing 8 options and my Color Drop Down List is
showing 8 options) I have a Master Page with a recordset pointing
to a Detail Page using the same recordset.
Master page works perfectly.
Master Recordset SQL:
SELECT products.itemID, products.category, products.styleno,
products.name, products.description, products.ourprice,
products.imageTH, products.image, coloroption.color,
sizeoption.size
FROM products, coloroption, sizeoption
WHERE category = 'chefcoats' AND
products.styleno=sizeoption.styleno AND
products.styleno=coloroption.styleno
GROUP BY products.styleno
ORDER BY styleno ASC
The Detail Recordset:
SELECT products.itemID, products.category, products.styleno,
products.name, products.description, products.ourprice,
products.imageTH, products.image, sizeoption.size,
coloroption.color
FROM products, sizeoption, coloroption
WHERE itemID=colname AND products.styleno=sizeoption.styleno
AND products.styleno=coloroption.styleno
I tried using the GROUP BY on the detail page, but then it
only showed one size and color from the dynamic drop down list. I
tried changing the field name "styleno" in the other tables to be
unique, however, I was using the table identifer. I tried using the
JOIN command instead of the WHERE clause and that didn't help
either.
On the detail page, the customer is supposed to click on the
Size box and see sizes XSM - 6XL ONLY ONE TIME. and then be able to
click on the Color option and see White, Black, Red ONE TIME.
Is this possible?
Thank you for giving your time to read this.!
EvieDo you have a link we can look at to see what you are trying
to do?
Dave
"EviePhillips" <[email protected]> wrote in
message
news:[email protected]...
> The CS3 Dreamweaver book says that the WHERE clause can
create a join for
two
> or more tables. The join was created, but the data is
repeating. I have
> searched the web and this forum and have not found the
answer.
>
> My Master page filters the recordset by Style No and
when a customer
clicks on
> a particular style, it sends him to the Detail page. All
the records are
> showing from all tables on the detail page from the
Dynamic List, except
they
> are showing multiple times (ex. Size table has 4 sizes
and Color table has
2
> colors - my Size Drop Down list is showing 8 options and
my Color Drop
Down
> List is showing 8 options) I have a Master Page with a
recordset pointing
to a
> Detail Page using the same recordset.
>
> Master page works perfectly.
> Master Recordset SQL:
> SELECT products.itemID, products.category,
products.styleno,
products.name,
> products.description, products.ourprice,
products.imageTH, products.image,
> coloroption.color, sizeoption.size
> FROM products, coloroption, sizeoption
> WHERE category = 'chefcoats' AND
products.styleno=sizeoption.styleno AND
> products.styleno=coloroption.styleno
> GROUP BY products.styleno
> ORDER BY styleno ASC
>
> The Detail Recordset:
> SELECT products.itemID, products.category,
products.styleno,
products.name,
> products.description, products.ourprice,
products.imageTH, products.image,
> sizeoption.size, coloroption.color
> FROM products, sizeoption, coloroption
> WHERE itemID=colname AND
products.styleno=sizeoption.styleno AND
> products.styleno=coloroption.styleno
>
> I tried using the GROUP BY on the detail page, but then
it only showed
one
> size and color from the dynamic drop down list. I tried
changing the
field
> name "styleno" in the other tables to be unique,
however, I was using the
table
> identifer. I tried using the JOIN command instead of the
WHERE clause and
that
> didn't help either.
>
> On the detail page, the customer is supposed to click on
the Size box and
see
> sizes XSM - 6XL ONLY ONE TIME. and then be able to click
on the Color
option
> and see White, Black, Red ONE TIME.
>
> Is this possible?
>
> Thank you for giving your time to read this.!
> Evie
>
> -
Outer join with a WHERE clause
hi, this is driving me round the bend. I thought i was ok with sql joins and the like, but im really struggling on this one.
I have table A (for argument sake tblRegion) and table B (tblBranch). if i want to return everything i would do something like this:-
select * from tblRegion join tblBranch on tblRegion.id=tblBranch.reg_id.
If i wanted to return all regions even if they do have a branch associated i would do something like this:-
select * from tblRegion left outer join tblBranch on tblRegion.id=tblBranch.reg_id.
My problem is, I want to return all Regions and use a WHERE clause to narrow the Branch results.
I've tried something like this but it doesnt work
select * from tblRegion left outer join tblBranch on tblRegion.id=tblBranch.reg_id WHERE branch.name like 'LONDON%'
Is there anyway i can return all branches where name is like LONDON, and STILL return all Region if there is no data for that Region?
Do i need to use a nested select statement maybe?
Many thanks in anticipation somebody will save me from my current madness. DavidCheck this link. It explains the most common problem/coding error while using outer join.
http://www.orafaq.com/node/855
Effectively in your case you need the following condition in your where clause
where nvl(branch.name,'LONDON') like 'LONDON%'
Hope that helps.
Regards
Raj -
Removing Outer Single Quotes for WHERE IN Clause from Join(Parameters)
Hello,
I am passing a multi-valued parameter into a dataset from a TypeBusiness dropdown list:
=join(Parameters!prmTypeBusiness.Value,",")
Here is the dataset query behind the TypeBusiness dropdown parameter list:
SELECT type_bus_code, bus_desc
FROM business
WHERE (type_bus_code IS NOT NULL)
Here is the WHERE clause from the main dataset query (dsMainData) which gets the parameter values:
WHERE WEKAVG.BUSINESS_CODE IN(@prmTypeBusiness)
Here is the error I get when selecting values from the TypeBusiness dropdown list then previewing the report:
"Cannot read the next data row for the dataset dsMainData.
Conversion failed when converting the nvarchar value '1,2' to data type smallint."
The value is a small int coming from the dataset query behind the TypeBusiness dropdown list, and the data type in the column expecting this value (in the main dataset query) is also a small int.
I have tried many things, including a replace in the =join(Parameters!prmTypeBusiness.Value,","), a replace in the WHERE clause, a Split function, CAST to varchar, have researched this online and cannot solve this error.
If someone could please help me save what little gray hairs I have left I would greatly appreciate any help, suggestion or point in the right direction.
Thanks,
BusterThank you for the sample, but it returns no records. Is there something I need to change in this snippet you sent?
DECLARE @prmTypeBusiness VARCHAR(20) = '1,2,4' -- say selected parameter values
DECLARE @business TABLE (type_bus_code INT, bus_desc VARCHAR(20))
INSERT @business SELECT 1,'A'
INSERT @business SELECT 2,'B'
INSERT @business SELECT 3,'C'
INSERT @business SELECT 4,'D'
;WITH CTE1
AS
SELECT CAST(('<i><j>' + REPLACE(@prmTypeBusiness, ',', '</j></i><i><j>') + '</j></i>' ) AS XML) CSV
),CTE2
AS
SELECT CAST(i.query('./text()') AS VARCHAR(100))CSV
FROM CTE1
CROSS APPLY CSV.nodes('/i/j') As x(i)
SELECT type_bus_code,
bus_desc
FROM @business
WHERE type_bus_code IN (SELECT * FROM CTE2)
sathya - www.allaboutmssql.com ** Mark as answered if my post solved your problem and Vote as helpful if my post was useful **. -
Creating WHERE clause for an outer join using DatabaseFilter
Hi all,
I read a post on thie group about constructing the WHERE clause for a RowSet Controls
SQL Query using the DatabaseFilter and this is what it said:
****************************************************************************The
following example shows adding part of a WHERE clause in an action method of a
page flow:
DatabaseFilter.FilterTerm term = new DatabaseFilter.FilterTerm(); term.sColumnName
= "name"; term.op = DatabaseFilter.opContains; // there are ops for equals, less
than, etc... term.value = form.getPartialName();
// You can also add sort terms for an ORDER BY clause allNames = dbControl.getNames(new
DatabaseFilter(new DatabaseFilter.FilterTerm[] {term}, null));
I am trying to create a where clause which uses a join like this:
Select * from x,y where x.id=y.id (+)
ie. All values from x.id but only corrosponding ones from y.id.
Is there any way to build this outer join query using the DatabaseFilter class
or am i forced to use a String which is contruct in my page flow as the where
clause?like so:
* @jc:sql command-type="grid"
* rowset-name="RFPSRowSet"
* max-rows="1000"
* statement::
* SELECT RFPS.RFP_ID,RFPS.NAME AS RFP_NAME,RFPS.FFO_NUMBER,RFPS.RFP_TYPE,RFPS.CFDA_NUMBER,COMPETITIONS.NAME
AS COMP_NAME,COMPETITIONS.COMPETITION_ID FROM RFPS,COMPETITIONS WHERE {sql: whereClause
} {sql: filter.getOrderByClause ()}
public RowSet getAllRfps(java.lang.String whereClause,DatabaseFilter filter)
throws SQLException;
and in my pageFlow action, i do the following:
StringBuffer whereClause= new StringBuffer();
whereClause.append("RFPS.RFP_ID = COMPETITIONS.RFP_ID (+)");
if ((form.getRfpTitle() != null) &&
(!form.getRfpTitle().equalsIgnoreCase("")))
whereClause.append(" AND UPPER(RFPS.NAME) LIKE %"+form.getRfpTitle().toUpperCase());
if ((form.getCfdaNumber() != null) &&
(!form.getCfdaNumber().equalsIgnoreCase("")))
whereClause.append(" AND RFPS.CFDA_NUMBER ="+form.getCfdaNumber());
if ((form.getFfoNumber() != null) &&
(!form.getFfoNumber().equalsIgnoreCase("")))
whereClause.append(" AND RFPS.FFO_NUMBER ="+form.getFfoNumber());
sortFilterService = SortFilterService.getInstance(getRequest());
DatabaseFilter filter=sortFilterService.getDatabaseFilter(getGridName());
log.debug("***********"+whereClause.toString()+"***********");
allRows = searchRfaAndComp.getAllRfps(whereClause.toString(),filter);
Thanks in advance for your help,
Regards,
Vik.Thanks for your reply. Just one more question....if we indeed are trying to use
a simple query and have a where clause like "select * from x where upper(x) like
{x}", how do we set the UPPER filter on the column using the database filter?
I see a IDENTIFIER.ISUPPER static field on that DatabaseFilter but am unsure how
to use it. Would appreciate any pointers .
Thanks again,
Vik
Eddie O'Neil <[email protected]> wrote:
Vik--
I believe that the approach that you describe below is the best one
for dealing with outer joins
with the DatabaseFilter.
Apologies for the limitation...
Eddie
vik wrote:
Hi all,
I read a post on thie group about constructing the WHERE clause fora RowSet Controls
SQL Query using the DatabaseFilter and this is what it said:
****************************************************************************The
following example shows adding part of a WHERE clause in an actionmethod of a
page flow:
DatabaseFilter.FilterTerm term = new DatabaseFilter.FilterTerm(); term.sColumnName
= "name"; term.op = DatabaseFilter.opContains; // there are ops forequals, less
than, etc... term.value = form.getPartialName();
// You can also add sort terms for an ORDER BY clause allNames = dbControl.getNames(new
DatabaseFilter(new DatabaseFilter.FilterTerm[] {term}, null));
I am trying to create a where clause which uses a join like this:
Select * from x,y where x.id=y.id (+)
ie. All values from x.id but only corrosponding ones from y.id.
Is there any way to build this outer join query using the DatabaseFilterclass
or am i forced to use a String which is contruct in my page flow asthe where
clause?like so:
* @jc:sql command-type="grid"
* rowset-name="RFPSRowSet"
* max-rows="1000"
* statement::
* SELECT RFPS.RFP_ID,RFPS.NAME AS RFP_NAME,RFPS.FFO_NUMBER,RFPS.RFP_TYPE,RFPS.CFDA_NUMBER,COMPETITIONS.NAME
AS COMP_NAME,COMPETITIONS.COMPETITION_ID FROM RFPS,COMPETITIONS WHERE{sql: whereClause
sql: filter.getOrderByClause ()}* ::
public RowSet getAllRfps(java.lang.String whereClause,DatabaseFilter
filter)
throws SQLException;
and in my pageFlow action, i do the following:
StringBuffer whereClause= new StringBuffer();
whereClause.append("RFPS.RFP_ID = COMPETITIONS.RFP_ID (+)");
if ((form.getRfpTitle() != null) &&
(!form.getRfpTitle().equalsIgnoreCase("")))
whereClause.append(" AND UPPER(RFPS.NAME) LIKE %"+form.getRfpTitle().toUpperCase());
if ((form.getCfdaNumber() != null) &&
(!form.getCfdaNumber().equalsIgnoreCase("")))
whereClause.append(" AND RFPS.CFDA_NUMBER ="+form.getCfdaNumber());
if ((form.getFfoNumber() != null) &&
(!form.getFfoNumber().equalsIgnoreCase("")))
whereClause.append(" AND RFPS.FFO_NUMBER ="+form.getFfoNumber());
sortFilterService = SortFilterService.getInstance(getRequest());
DatabaseFilter filter=sortFilterService.getDatabaseFilter(getGridName());
log.debug("***********"+whereClause.toString()+"***********");
allRows = searchRfaAndComp.getAllRfps(whereClause.toString(),filter);
Thanks in advance for your help,
Regards,
Vik. -
Outer join with where clause in the universe
Hi,
I have two tables such as:
Patient Table (P) Territory Table (T)
P. Alignment ID -------------------------- T.Alignment ID
P. Patient ID T. Region
Two tables are joined on alignment ID, follow is how the data looks like
When i run the query only on Patient Table i get the following
e.g.
Select P.Patient ID, P.Alignment ID
from Patient Table (P)
Where P.Data_date=P.Latest data date
----Note that there is a Where clause here always & i get the following result
P.Patient ID P.Alignment ID
1 1a
2 2a
3 3a
4 Null
5 Null
Now when i join two tables on Alignment ID
e.g.
Select P.Patient ID, P.Alignment ID,T.Region
from Patient Table (P)
LEFT OUTER JOIN Territory Table (T)
ON P. Alignment ID = T.Alignment ID
Where P.Data_date=P.Latest data date
AND T.Data_date=T.Latest data date
Following is the result:
P.Patient ID P.Alignment ID
1 1a
2 2a
3 3a
Even with the left outer join it is not brining in the Null values , it seems that because of the WHERE clause the LEFT OUTER is working as a INNER join.
How can i get the Null rows with my join to the territory table ?
Please Advise,
Thanks,
Sheikhits not letting me atatched the excel extract but the data is simple as i shown above e.g.
Patient Table (P) Territory Table (T)
P. Alignment ID -------------------------- T.Alignment ID
P. Patient ID T. Region
Two tables are joined on alignment ID, follow is how the data looks like
When i run the query only on Patient Table i get the following
e.g.
Select P.Patient ID, P.Alignment ID
from Patient Table (P)
Where P.Data_date='01-OCT-2014'
----Note that there is a Where clause here always & i get the following result
P.Patient ID P.Alignment ID
1 1a
2 2a
3 3a
4 Null
5 Null
Now when i join two tables on Alignment ID
e.g.
Select P.Patient ID, P.Alignment ID,T.Region
from Patient Table (P)
LEFT OUTER JOIN Territory Table (T)
ON P. Alignment ID = T.Alignment ID
Where P.Data_date='01-OCT-2014'
AND T.Data_date='01-OCT-2014'
Following is the result:
P.Patient ID P.Alignment ID
1 1a
2 2a
3 3a
Now the whole issue is that the condition in the WHERE clause is making it act like a inner join and iw ant the NULL rows to appear
Sheikh -
Where clause on right side table of a left join
I was told by someone that a where clause on the right side table of a left join is bad SQL. I have looked around and found a great article for DB2. I am not sure if this is 100% correct for SQL Server so would like to find a good detailed
article on the topic.
Thank youI was told by someone that a where clause on the right side table of a left join is bad SQL. I have looked around and found a great article for DB2. I am not sure if this is 100% correct for SQL Server so would like to find a good detailed
article on the topic.
Thank you
I'm going to be blunt here so if you get offended easily please stop reading now.
That has got to be some of the dumbest advice I've seen in a while. Such a query serves a specific purpose, there's no good or bad to it. Following is a classic example:
select distinct
CustomerID
from Customer as c
left join Orders as o
on c.CustomerID = o.CustomerID
and o.OrderDate > dateadd(day, -90, getdate())
where o.CustomerID is null
The above hypothetical query, which includes a where clause which targets the right table in a left join, returns all customers which have not placed an order in the past 90 days. It's a perfectly valid query which serves a key business purpose and
I challenge anyone to justify why they claim it is "bad SQL".
Such a query will execute efficiently given appropriate indices. There's simply no justification for such a blanket statement about where clauses and outer joins. -
Generate a where clause with outer join criteria condition: (+)=
Hi,
In my search page, I use Auto Customization Criteria mode, and I build where clause by using get Criteria():
public void initSrpQuery(Dictionary[] dic, String userName) {
int dicSize = dic.length;
StringBuffer whereClause = new StringBuffer(100);
Vector parameters = new Vector(5);
int clauseCount = 0;
int bindCount = 1;
for(int i=0; i < dicSize; i++){
String itemName = (String)(dic.get(OAViewObject.CRITERIA_ITEM_NAME));
Object value = dic[i].get(OAViewObject.CRITERIA_VALUE);
String joinCondition = (String)dic[i].get(OAViewObject.CRITERIA_JOIN_CONDITION);
String criteriaCondition = (String)dic[i].get(OAViewObject.CRITERIA_CONDITION);
String criteriaDataType = (String)dic[i].get(OAViewObject.CRITERIA_DATATYPE);
String viewAttributename = (String)dic[i].get(OAViewObject.CRITERIA_VIEW_ATTRIBUTE_NAME);
String columnName = findAttributeDef(viewAttributename).getColumnNameForQuery();
if((value != null) /*&& (!("".equals((String).trim())))*/){
if(clauseCount > 0){
whereClause.append(" AND ");
whereClause.append(columnName + " " + criteriaCondition + " :");
whereClause.append(++bindCount);
parameters.addElement(value);
clauseCount++;
If I want to generate following where clause:
select
,emp.name
,emp.email
,emp.salesrep_number
,comp.name
,gs.srp_goal_header_id
,gs.status_code
,gs.start_date
,gs.end_date
from g2c_goal_shr_emp_assignments_v emp
,jtf_rs_salesreps rs
,xxg2c_srp_goal_headers_all gs
,cn_comp_plans_all comp
where 1 = 1
and rs.salesrep_id = gs.salesrep_id (+)
and gs.comp_plan_id = comp.comp_plan_id (+)
and gs.period_year (+) = :1 -- :1 p_fiscal_year
How can I generate a where clause with outer join : gs.period_year (+) = :1 ? Will I get '(+)=' from get(OAViewObject.CRITERIA_CONDITION)?
thanks
LeiIf you are using SQL-Plus or Reports you can use lexical parameters like:
SELECT * FROM emp &condition;
When you run the query it will ask for value of condition and you can enter what every you want. Here is a really fun query:
SELECT &columns FROM &tables &condition;
But if you are using Forms. Then you have to change the condition by SET_BLOCK_PROPERTY.
Best of luck! -
Order of Predicates and Joins in a where Clause
I always specify the join conditions and then predicates in where clause . But when i placed the predicates first and then joins the response was quicker . I compared the execution plan and each has a different approach .
Is it true in all cases or it doesn't matter ? Which one is better ? In the following examples I usually follow the first approach but when i tried the second one it was faster .
Query 1
select t1.something from
table1 t1 , table2 t2
where t1.id=t2.id
and t1.year = 2009
Query 2
select t1.something from
table1 t1 , table2 t2
where t1.year = 2009and
and t1.id=t2.id
Edited by: user561066 on Sep 24, 2010 11:57 AMWelcome to the forum.
As SomeoneElse already asked: mentioning your database version is crucial when it comes to these types of questions.
So just be default always post the result of:
SQL> select * from v$version;when asking a question.
Find more information here, it explains clearly what information is needed from you to post:
How to post a SQL statement tuning request HOW TO: Post a SQL statement tuning request - template posting
Execution plans, database version, optimizer settings.... -
How to change operator of join conditions in where clause?
Hello
I have a situation... I want to change the operator between each join conditions in the where clause when these join conditions are not from the same join..
For example, I have the following schema:
Dim1 ------ DimA -------Fact1
Dim1-------DimB -----Fact1
So DimA and DimB are aliasas of one dim table, but the join is different.
Now if I run this model, what I will get in the where clause of the query is:
Where Dim1 = DimA and Dim1 = DimB and DimA= Fact1 and DimB = fact1.
Is there a way I can change these "and" operator to "OR", so that the where clause would look like this: Where Dim1 = DimA and Dim1 = DimB and DimA= Fact1 OR DimB = fact1?
This is different from simply changing the join operator within the same join, because these are different joins and I'd like to control how they relate to each other..
Please help
ThanksSometimes, business rules are complex, so there isn't always a way to simplify things. Is your issue that it's complex and error prone, or is it performance due to the OR clauses?
One possibility that will at least make it easier to test and debug is something like this: (pseudocode)
From Table1 Inner join Table2 on x=y etc.etc.
CROSS APPLY
(Select case when a=b and (c=d or e=f) then 1 else 0 end) as Situation1
, case when h=i or j = k then 1 else 0 end) as situation2
, case when l = m then 1 else 0 end) as situation 3
) as CA_Logic_Simplifier
Where situation1 = 1 and situation2 = 1 and situation3 = 1
Although you could say, "Hey, this is basically doing the same thing as before", this approach would be far easier to test and debug, because you can at a glance look at the values for situation1, 2, 3, etc. to see where errors are being introduced.
The cross apply makes the columns situation1/2/3 "instantiated", so they are usable in the where clause. Divide and conquer.
Maybe you are looking for
-
How do i create/combine my mac id with my iPhone id?
i wanted to download an app form app store and was asked for my id.. apperntly my iPhone id is limited to my country's app store and my email is in use for that id... how do i create/combine my mac id with my iPhone id so i can download apps from app
-
Guys, I ran another F110 for ACH payment.The propsal gives the following messages,Anyone please guide me how to create payment media and variant for format ACH. Regards Shaun Step 002 started (program SAPFPAYM_SCHEDULE, variant &0000000000369, user
-
I use Acrobat 8. When I edit and save a PDF, I get "squares" instead of letters throughout the document. Anyone have a solution?
-
Custom Compressor settings not showing in Final Cut Pro X?
I have FInal Cut Pro X and Compressor 4.1. I've made a few custom settings in Compressor and can even see them in Library/Application Support/Compressor/Settings but they don't show up when I click on 'Export using Compressor Settings' in Final Cut P
-
Why won't my Home Sharing work?
I have a MacBook Pro running Lion. Home Sharing is turned on and logged in on iTunes and iTunes is running, still I cannot access my computer's Library on my Apple TV (2 gen) which also has Home Sharing turned on and logged in.. It used to work eve