Column data restriction based on join condition
All,
SELECT e.ename,
d.dname,
e.job,
e.comm, e.sal
FROM emp e,
dept d
WHERE e.deptno=d.deptno
AND e.empno =7788
AND e.comm IS NOT NULL;
In this query, if the comm for the empno=7788 is not null, then i am able to retrive the record, If comm is not null, display the entire record along with comm details, if it is null, display the entire record without comm value(may be as null).
If commission is not null, then display the entire record, if it is null, then for e.comm, e.sal I want to display null values.
PS: I am in a situtation like this kind of. Kindly give me some idea.
Thanks
Thank you Frank and Sorry for not so clear in explanation.
SQL> desc demois_wo_routing
Name Null? Type
ORG_ID NUMBER
ASSIGNED_TO VARCHAR2(10)
COMMENTS VARCHAR2(55)
DUE_DATE DATE
ENTER_DATE NOT NULL DATE -- is the APPROVED_DATE
ENTER_USER VARCHAR2(30) -- is the APPROVER_NAME
PRIORITY NUMBER
START_DATE DATE
STATUS NOT NULL VARCHAR2(10)
WO_NUMBER NOT NULL VARCHAR2(10)
SQL> desc demois_sr_routing
Name Null? Type
ORG_ID NUMBER
ASSIGNED_TO VARCHAR2(10)
COMMENTS VARCHAR2(55)
DUE_DATE DATE
ENTER_DATE NOT NULL DATE
ENTER_USER VARCHAR2(30)
PRIORITY NUMBER
REQ_NUMBER NOT NULL VARCHAR2(10)
START_DATE DATE
STATUS NOT NULL VARCHAR2(10)
SQL> select enter_user,wo_number,enter_Date,status from demois_wo_routing where wo_number='WO000853';
ENTER_USER WO_NUMBER ENTER_DAT STATUS
E60075334 WO000853 14-MAY-13 APPROVED
C10000001 WO000853 09-APR-13 OPEN
C10000001 WO000853 09-APR-13 ASSIGNED
E60075373 WO000853 09-APR-13 PND APPRVL
SQL> select enter_user,req_number,enter_date,status from demois_sr_routing where req_number=(select req_number from demois_req where wo_number='WO000853');
ENTER_USER REQ_NUMBER ENTER_DAT STATUS
E60075373 SR000818 09-APR-13 SCHEDULED
E60075334 SR000818 14-MAY-13 SCHEDULED
C10000001 SR000818 09-APR-13 SCHEDULED
C10000001 SR000818 09-APR-13 SCHEDULED
SQL> SELECT fm.first_name || ' ' || fm.last_name AS approver_name,
2 fpc.communication_value AS approver_cell
3 FROM demo_person fm, demo_person_communication fpc
4 WHERE fm.person_code = 'E60075334' --ENTER_USER from FSR/ FWR table
5 AND fm.person_id = fpc.person_id
6 AND fpc.communication_type = 'Telephone';
APPROVER_NAME
APPROVER_CELL
Nicy Varghese
44952937
SQL> SELECT fm.first_name || ' ' || fm.last_name AS approver_name,
2 fpc.communication_value AS approver_cell
3 FROM demo_person fm, demo_person_communication fpc
4 WHERE fm.person_code =
5 (SELECT enter_user
6 FROM demois_wo_routing
7 WHERE wo_number = 'WO000853' AND status = 'APPROVED')
8 AND fm.person_id = fpc.person_id
9 AND fpc.communication_type = 'Telephone';
APPROVER_NAME
APPROVER_CELL
Nicy Varghese
44952937
ACTUAL QUERY :---- If i run the below query i will definitely get a record of WO_NUMBER along with the other details.
SELECT w.wo_number,
DECODE (NVL (p.print_wo_barcode_flag, 'N'),
'Y', '*' || w.wo_number || '*',
NULL
) barcode_wo_number,
INITCAP (w.maint_type) maint_type, INITCAP (w.wo_status) wo_state,
w.priority, w.modify_date, w.start_date, w.due_date,
INITCAP (w.description) description, w.method, w.crew,
INITCAP (w.craft) craft, w.assigned_to, w.est_hours,
DECODE (w.req_type,
'S', 'Service',
'P', 'PM',
'W', 'Project',
'T', 'Standing WO'
) req_type,
w.req_number, INITCAP (w.requestor) requestor, w.telephone,
w.mail_code, w.department, w.cp_number, w.site, w.building,
NVL (w.phase, 0) phase, w.FLOOR, w.room, w.equipment,
INITCAP (w.close_comments) close_comments, w.alt_requestor,
w.alt_telephone, w.alt_department, w.alt_mail_code, w.schedule_user,
DECODE (w.equipment,
NULL, NULL,
'*' || w.equipment || '*'
) equip_barcode,
INITCAP (e.NAME) employee_name, w.schedule_date, w.pl_number,
INITCAP (q.nomenclature) nomenclature, INITCAP (q.mfr) mfr,
INITCAP (w.nonavailable_time) nonavailable_time, w.enter_user,
a.asset_class_code, INITCAP (a.description) asset_class_description
FROM demois_emp e,
demois_equip q,
demois_req w,
demois_fmm_config p,
demois_asset_class a
WHERE w.wo_number IS NOT NULL
AND NVL (w.asset_type, 'N') = 'N'
AND w.equipment = q.equipment(+)
AND w.assigned_to = e.employee(+)
AND (w.assigned_to = :p_assigned_to OR :p_assigned_to IS NULL)
AND ( (:p_marked_to_print = 'Y' AND w.print_ticket = 'Y')
OR (:p_wo_number IS NOT NULL)
AND (w.site = :p_site OR :p_site IS NULL)
AND (w.crew = :p_crew OR :p_crew IS NULL)
AND (w.craft = :p_craft OR :p_craft IS NULL)
AND (w.maint_type = :p_maint_type OR :p_maint_type IS NULL)
AND (w.req_type LIKE NVL (:p_req_type, '%'))
AND (w.wo_number LIKE NVL (:p_wo_number, '%'))
AND q.asset_class_id = a.asset_class_id(+)
ORDER BY wo_number;
The above is the sample data for my logic. The last one is the original query which am modifying with the tables listed above. The last query will return a record based on WO_NUMBER. Now i have to passing the WO_NUMBER to FWR table checking whether it is in APPROVED status or not. If not need to in FSR table with the associated SR ( req_number) for that WO_NUMBER.
If there is a record in 'APPROVED' state, need to display the approver name from FP and FPC tables by passing value of the ENTER_USER from FSR / FWR. Till now it is fine , if the STATUS is 'APPROVED'.
The problem here is, there may a situation where the WO_NUMBER ( or respective SR number) will not be in 'APPROVED' status in both the tables. In this case also i need to get the record as usual like if i run the last query (ACTUAL QUERY).
There is no direct relation between the FSR and FWR tables here. Only DEMOIS_REQ table has REQ_NUMBER (SR000818) and WO_NUMBER ( WO000853 ).
Again sorry, If i am not clear enough.
Thanks in advance.
Similar Messages
-
Creating a simple ALV report based on join condition
Dear All
SAP Version: ECC6 EHP7
I wan to create simple ALV report based on join condition. can anyone provide me the complete steps to create this report.
Regards,Hi Syed,
Please check the link,
ALV report - Joining 2 tables
Regards,
Prakash. -
Column hiding /unhiding based on a condition
I have a report in which I want to add "State" Column. But it show up only when "Region" = 'Northeast'. And do not show State for other "Region"
So basically, I want to hide "State" column dynamically based on condition where "Region"='Northeast'.
Would Siebel On Demand let us do Column hiding /unhiding based on a data condition?
Please let me know if this is possible.
Thanks
RakeshI don't think SOD lets hide/unhide a column based on a condition. All you can do is restrict the number of rows using a filter.
-
Oracle Business Intelligence How to choose data set based on a condition
Hi,
I am using Oracle Business Intelligence for creating reports, i am facing a situation where i have two quries (data sets in BI), one to display a Failure message and other to fetch data from the table to be displayed in the report.
The problem is i am unable to choose which data set to run based on a condition. How to use a condition based on which the dataset will be run
For example : i will read a table column value if it is 'S' means success, then i have to run the dataset to fetch the data from the table.
If the column value has 'F' then i have to run the dataset which will display failure message
Please let me know if any of you have any idea on this
Thanks in advance
MuthukumaranHi Chinna,
You have to use some scripting as well as coding to perform the tasks listed by you. First of all make your form Dynamic, In your Adobe lifecycle Designer, open your form,
Goto, File --> Form Properties,
Goto the Defaults tab,
Select "Dynamic PDF" for the XDP Preview Format:
Click OK.
This setting will now allow dynamicity in your Form, when you view it in PDF Preview tab.
For Hiding/Unhiding the fields/SF, you can use the presence property and set it based on the conditions. like:
if (this.rawValue == null)
TextField1.presence = "hidden";
For your second task, you may map a method corresponding to onSubmit event of the IF and write the code to create the workflow and make RFC call here.
For third one, you need to convert the PDFObject from Binary context into a byte array and save it at appropriate location.
Hope I have answered all your queries.
Cheers,
Arafat -
Column value coloring Based on the condition in ssrs 2008
Hi,
I need to change color formating based on below conditions
Red if <=28 days or > 65 days
Green if >28 and <=60 days
Yellow if > 60 days and <=65 days
<=0 No color
I tried with below IIF condition it's not working.
=iif(Fields!HDSI13.Value<=0,
"No color",iif((Fields!HDSI13.Value<=28
or Fields!HDSI13.Value>64),"Red",iif((Fields!HDSI13.Value>29
and Fields!HDSI13.Value<=60),"Green",iif((Fields!HDSI13.Value>60
and Fields!HDSI13.Value<=65),"yellow",Nothing))))
Can any one help me on this.
Thanks,
Manasa.
Thank You, Manasa.Vhi all,
When i wrote like this in table report ...woking fine.
=iif(((Fields!HDSI13.Value<=28
and Fields!HDSI13.Value>0)
or Fields!HDSI13.Value>64),"Red",iif((Fields!HDSI13.Value>=29
and Fields!HDSI13.Value<=60),"Green",iif((Fields!HDSI13.Value>=61
and Fields!HDSI13.Value<=65),"yellow",iif(Fields!HDSI13.Value<=0,"Nocolor",""))))
Thank You, Manasa.V -
Report data restriction based on SAP ID - Authorization in BI 7.0
Hi Friends,
In our project the requirement of restriction of report is as follows.
There are two reports
1. Carrier View Report
2. Carrier Drilldown Report
Carrier View which is on Multiprovider is main report and Carrier Drilldown report, which is on DSO (ODS) is RRI report.
Carrier Vendors (these are vendors taking care of transporting the goods to customer locations from plant) will be viewing these reports. We have a master data maintained for Carriers as Carrier ID. The report has this Carrier ID in rows. Each carrier vendor would be given a SAP ID for logging into BW WEB reports.
Security Requirement: When a carrier execute report, the data in the report should be restricted to Carrier ID associated with the SAP ID which he is using.
Kindly suggest us the steps to do it, I am not basis person, but I need to help him.
Thanks and regards,
BalarajHi Balaraj,
You can use <a href="http://help.sap.com/saphelp_nw70/helpdata/en/66/019441b8972e7be10000000a1550b0/frameset.htm">Analysis Authorizations</a> in BI. Use transaction RSECADMIN to create authorizations and user assignments.
You need to declare Carrier ID Infoobject as Authorization relevant. Analysis authorizations are not based on authorization objects. Instead, you create authorization for each carrier that include Carrier ID characteristic and some restricted value(s) for the characteristic. You can then assign this authorization to one or more users(SAP IDs). When ever a query with Carried ID is executed, It checks for the analysis authorizations and hence he can acess only those values that are assigned in his own authorization.
Instead of assigning the corresponding Carrier IDs values for each authorization manually, you can create a single authorization for Carrier ID and fill in the values of the authorization using <a href="http://help.sap.com/saphelp_nw70/helpdata/en/91/a62c42fb6fdd2ce10000000a1550b0/frameset.htm">Authorization variables</a>. In this case in the customer exit you need to use the master data maintenance of SAP ID and CARRIER ID and fill in the values of E_T_RANGE depending on the user name SY_UNAME.
Assign points if you find it helpful.
Regards, Uday -
Date difference based on the conditions is giving wrong values
Hi,
In creating the formula for conditional date difference calculation,
i.e.,
if (sto date is 0) then (act date - mat rel date) else (sto date is not equal to 0) then (sto date - mat rel date)
So I tried with,
(sto date == 0) * (act date - mat rel date) + (sto date <> 0) * (sto date - mat rel date)
But I am getting a wrong value even with decimals as days can't be in decimals. Please suggest where I am going wrong in calculation.
Thanks,
Best Regards,
Darshan MSHi Darshan,
First of all, were the dates converted already to keyfigure?
If not, please check:
Convert a Characteristic into a Key Figure (BEx)
If they were already converted, try this:
(sto date == 0) * (act date - mat rel date) + (sto date - mat rel date)
Regards,
Loed -
Inserting new columns based on the condition!
Hi guys,
I have a very simple query like the following…
SELECT table2.column_code2,
table2.column_description2,
table2.column_code1,
table1.column_description1
FROM database_001.table2 table1 LFET OUTER JOIN database_001.table2 table1 on (table2.column_code1 = table1.column_code1)
From this query, its returning me a result set of something like below:
column_code1 column_description1 column_code2 column_description2
RO1 BOOK RL1
PDF/ECOPY
RO2 PAPER RL2
CONFERENCE
RO5 JOURNAL
RL11 OTHER
Now, on the above query I want to insert three extra columns with the name (status, location and contact) where the results in the extra three columns would be based on the conditions I want to define in the query based on the above results…
Something for example (sorry, I am not trying to write a condition: my question is how to write it),
if column_code1 = RO1 and column_description2 = PDF/ECOPY on status column it should return a value ‘ONLINE’ & on location column it should return ‘WEB’ and on contact column it should write ‘BOB’.
Also,
if column_code1 = RO5 and column_description1 = JOURNAL on status column it should return a value ‘ON PRESS FOR PRINT’ & on location column it should return ‘S.R STREET, LONDON’ and on contact column it should write
‘SMITH’ like below result…so the final output should be the top four columns and the extra three columns…I hope someone can help me into this…thanks a lot…
status location
contact
ONLINE WEB
BOB
ON PRESS FOR PRINT S.R STREET, LONDON SMITHHi artistdigital,
you can use case statment for same in sql server. MSDN link - > http://technet.microsoft.com/en-us/library/ms181765.aspx
Try code like this:
SELECT table2.column_code2,
table2.column_description2,
table2.column_code1,
table1.column_description1,
case when column_code1 = 'RO1' and column_description2 = 'PDF/ECOPY' then 'ONLINE'
when column_code1 = 'RO5' and column_description1 = 'PDF/ECOPY' then 'ON PRESS FOR PRINT'
end as [status],
case when column_code1 = 'RO1' and column_description2 = 'PDF/ECOPY' then 'WEB'
when column_code1 = 'RO5' and column_description1 = 'PDF/ECOPY' then 'S.R STREET, LONDON'
end as [Location],
case when column_code1 = 'RO1' and column_description2 = 'PDF/ECOPY' then 'BOB'
when column_code1 = 'RO5' and column_description1 = 'PDF/ECOPY' then 'SMITH'
end as [contact]
FROM table2
join table1
on table2.column_code1 = table1.column_code1
Regards Harsh -
hello all,
can anyone help me write an outer join b/n the two tables below. The joining condition has if's and or's.
table 1 has 2 million rows, table 2 is very small
TABLE1
CUSTOMER_ID
CITY
STATE
1
SKOKIE
IL
2
CHICAGO
IL
3
CARY
NC
ERIE
PA
PHILLY
PA
CHARLOTE
NC
2 MILLION
CITYXY
STATEX
TABLE2
CITY
STATE
CONTACT
IL
OJO
ERIE
BRITT
PA
MIKE
PITTSBURG
PA
HILTON
N043
TAT
affi
B
affi
R
b0b
Q
b0b
CHARLOTE
NC
b0b
problem :: for all the data in table1, I need to find out the CONTACT from table 2 And the join condition would be as below
1. either both TABLE1.CITY=TABLE2.CITY AND TABLE1.STATE=TABLE2.STATE and get CONTACT
OR
2. TABLE1.CITY=TABLE2.CITY AND TABLE2.STATE IS NULL and get the value of CONTACT
OR
3. TABLE1.STATE=TABLE2.STATE AND TABLE2.CITY is null and get the value of CONTACT
I need a query like this
SELECT A.CUSTOMER_ID, A.CITY, A.STATE, B.CONTACT
FROM TABLE1 A, TABLE2 B
WHERE (join condition fitting in the 3 condition mentioned above)Dear OP,
Do you want something like this?
> with t1 as
-- Start of SAMPLE DATA
(select 1 CUSTOMER_ID, 'SKOKIE' CITY, 'IL' STATE from dual union
select 2, 'CHICAGO', 'IL' from dual union
select 3, 'CARY', 'NC' from dual union
select 4, 'ERIE', 'PA' from dual union
select 5, 'PHILLY', 'PA' from dual union
select 6, 'CHARLOTE', 'NC' from dual)
t2 as
(select null CITY, 'IL' STATE, 'OJO' CONTACT from dual union
select 'ERIE', null, 'BRITT' from dual union
select null, 'PA', 'MIKE' from dual union
select 'PITTSBURG', 'PA', 'HILTON' from dual union
select 'N043', 'TAT', 'affi' from dual union
select null,'B', 'affi' from dual union
select null,'R', 'b0b' from dual union
select null,'Q', 'b0b' from dual union
select 'CHARLOTE', 'NC', 'b0b' from dual
--- END IF SAMPLE Data
select * from t1 full outer join t2
on ( nvl(t1.city,t2.city) = nvl(t2.city,t1.city)
and nvl(t1.state,t2.state) = nvl(t2.state,t1.state) )
order by 1,2,3,4
CUSTOMER_ID CITY STATE CITY STATE CONTACT
1 SKOKIE IL IL OJO
2 CHICAGO IL IL OJO
3 CARY NC
4 ERIE PA ERIE BRITT
4 ERIE PA PA MIKE
5 PHILLY PA PA MIKE
6 CHARLOTE NC CHARLOTE NC b0b
N043 TAT affi
PITTSBURG PA HILTON
B affi
Q b0b
R b0b
12 rows selected
Elapsed: 00:00:00.112
Hope this is helpful. If not please let us know what is you desired result (sample) if your data was like above?
vr,
Sudhakar -
How to create a column based on a condition ?
Hi all,
I am trying to create a stored procedure that will return ID,Name and a column of type bit called called checked based on a condition
please review my code and tell me what is wrong with it
ALTER PROCEDURE [dbo].[SelectStoresNames]
AS
BEGIN
WITH locations_CTE ( ID, Name, Checked)
AS
select loc.ID,loc.Name,
(case when loc. ID in (select distinct a.StoreId
from mPromoteStores a
inner join mPromote b
on a.PromoteId=b.PromoteId
where b.promoId=144120) then 1 else 0 end as [Checked])
FROM [dbo].[mLocations] loc where SchedulePullEnabled=1 order by Name
Select *
from locations_CTE
ENDPlease post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. You have no idea!
Temporal data should use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect.
This is minimal polite behavior on SQL forums.
>> I am trying to create a stored procedure that will return store_id, store_name and a column of type bit called “checked” based on a condition <<
I fixed the vague, useless, generic data elements, made wild guesses on the DDL you did not post and got rid of the assembly language bit flags (https://www.simple-talk.com/sql/t-sql-programming/bit-of-a-problem/)
1. IN (SELECT DISTINCT ..) is redundant
2. aliases in alphabetic order are no help for maintaining code
3. What is that “m” prefix? Better not be metadata...
4. We also do not use “-cte” postfixes; tell us what the table is and not how you got it. This is another version of the “vw-” or “Volkswagen” design flaw for views.
5. “promote” is a verb, so how can it have an identifier? Entities have identifiers. A set of “Promotions” could have a “promo_id”, but this might be a typo ..
6. Is “schedule_pull_enabled” another assembly language flag? I have the horrible feeling your unseen schema is not in 1NF ...
Since you did not post DDL here is as far as I can get ..
CREATE PROCEDURE Select_Stores_Names
AS
SELECT PS.store_id, PS.store_name
FROM Promote_Stores AS PS,
Promotes AS P
WHERE PS.promote_id = P.promote_id
AND P.promo_id = 144120 -- promo vs promote?
AND ???;
Want to follow the forum rules and try again?
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
Partition based on join in data warehouse env.
Hi,
I am working on DW environment and am quite new to it.
The scenario is like there are 2 fact tables and one dimension table.
Now I need to partition both the fact tables based on the dates in Dim table. My problem is there is no date mentioned in fact table other then Surogate keys in fact tables.
Is it possible to partition the table by using join condition between fact table and Dim table and if yes how?
The structure of tables are as follows.
Please help!
Daily sales fact table
planned shipment date sk NUMBER PK1, FK1
source system identifier VARCHAR2(50) PK2
sales type indicators sk NUMBER PK3, FK3
ship-to-customer sk NUMBER PK4, FK4
product sk NUMBER PK5, FK5
ship-from-location sk NUMBER PK6, FK6
quantity in primary units NUMBER(14,3)
quantity in 9LE NUMBER(14,3)
Daily Sales Order Fact
sales invoiced date sk NUMBER PK1, FK1
source system identifier VARCHAR2(50) PK2
sales type indicators sk NUMBER PK3, FK3
ship-to-customer sk NUMBER PK4, FK4
product sk NUMBER PK5, FK5
ship-from-location sk NUMBER PK6, FK6
quantity in primary units NUMBER(14,3)
quantity in 9LE NUMBER(14,3)
Sales order month Dim
sales order month sk NUMBER PK1
sales order month full name VARCHAR2(50)
sales order month number NUMBER(2)
sales order month calendar year NUMBER(4)
sales order month financial year NUMBER(4)
sales order month start date DATE AK1
sales order month end date DATE
sales order month end date sk NUMBER
days in sales order month NUMBER(2)
event number NUMBER(12)
last update date DATE
Thanks in advance.If you take care that the synthetic key values for you date are assigned in ascending order with the date value then you can range equi-partition by range on both of them without too much trouble.
Personally I don't use synthetic values as PK's on dates, partly for this very reason. -
hi ,
i need help on the below scenario ,
we have a web dynpro table with different columns, now based on new business requirement one of the column need to
dynamically editable or non editable for different row.
for ex :
Field 1
Field 2 ( Dynamic field )
Field 3
Field 4
Data 11
Data 12 ( Editable with Drop down )
data 13
data 14
Data 21
Data 22 ( Non editable )
Data 23
data 24
Data 31
data 32 ( Editable with drop down )
data 33
data 34
how to achieve this ? please help on this.
Thanks in advance
Thanks
ManishManish,
there is no proper way to insert two Cell Editors in a column(except variants), have a look on below scenario, it may help.
add one more attribute to your table context node for read-only.
create dropDown as celleditor for table and bind with newly created attribute to read-only property of dropdown.
before binding data to table, check the condition then mention readonly value abap_true / false.
@ we can achieve by the use of Variants.
for ex :
Data 11
Data 12 ( Editable with Drop down)
data 13
read-only - abap_false
Data 21
Data 22 ( Non editable, dropdown )
Data 23
read-only - abap_true
Data 31
data 32 ( Editable with drop down )
data 33
read-only - abap_false -
Infoset Join condition on Key feilds and data fields
Hi Guys,
I have a requirement to biuld the Info set with join conditon on two DSO's the info objects which i am using in the JOin condition are defined as data fieds in one DSO and defined as key fields in another DSO, is it possible to define join condition on key fields and data fields.
The two info objects are
0AC_DOC_NO
0ITEM_NUM
These two info objects are defined as data fields in DSO : 0LIV_DS1 Invocie verificaion
key fields in DSO: 0FIAP_0o3 FI AP Line Item
Please suggest me is it possible to define join the condtion on the data fields and key feilds.
Thanks
Best regards
SGHi
yes you can create join, you will get any issue in reporting level.
example: Say i want to create Info Set on 0MATERIAL and Sales DSO.
In 0MATERIAL Info Object it is key filed, but in my DSO 0MATERIAL is data field.Still we can create
Creation of join is dependent on fields common in your source objects.
check out the below document
http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/2f5aa43f-0c01-0010-a990-9641d3d4eef7?QuickLink=index&overridelayout=true
Regards,
Venkatesh
Edited by: Venkateswarlu Nandimandalam on Sep 27, 2011 2:26 AM -
Joins on different fields based on a condition
Hi,
I have 2 tables, each consists of 5 fields, based on Field3's data, I want to join either F1 & F2 or F4 & F5.
I have given below the field creation and sample data for your reference. When I run the SQL with "case when .."
statement, it gives "ORA-00905: missing keyword" error.
I can do this by splitting into 2 separate SQL statements one for F1 & F2 and the other for F4 and F5.
Is there any other better way of doing it in a single SELECT statement?
Please share your views, thank you.
create table tmp_a
(f1 varchar2(50),
f2 varchar2(50),
f3 char(1),
f4 varchar2(50),
f5 varchar2(50))
create table tmp_b
(f1 varchar2(50),
f2 varchar2(50),
f3 char(1),
f4 varchar2(50),
f5 varchar2(50))
begin
insert into tmp_a
values('R1', 'abc', 'L', 'A1', 'B1');
insert into tmp_a
values('R2', 'lkj', 'L', 'A2', 'B2');
insert into tmp_a
values('R3', 'qwe', 'M', 'A3', 'B3');
insert into tmp_a
values('R4', '123', 'M', 'A4', 'B4');
insert into tmp_b
values('R3', 'qwe', 'L', 'A1', 'B1');
insert into tmp_b
values('R2', 'lkj', 'L', 'A2', 'B2');
insert into tmp_b
values('R4', '123', 'M', 'A3', 'B3');
insert into tmp_b
values('R1', 'abc', 'M', 'A3', 'B3');
commit;
end;
select * from tmp_a;
select * from tmp_b;
select a.*, b.*
from tmp_a a, tmp_b b
where a.f1 = b.f1 and a.f2 = b.f2;
select a.*, b.*
from tmp_a a, tmp_b b
where a.f4 = b.f4 and a.f5 = b.f5;
select a.*, b.*
from tmp_a a, tmp_b b
where case when a.f3 = 'L' then
a.f4 = b.f4 and a.f5 = b.f5
else
a.f1 = b.f1 and a.f2 = b.f2
end;Maybe something like:
SQL> SELECT a.*, b.*
2 FROM tmp_a a, tmp_b b
3 WHERE CASE
4 WHEN a.f3 = 'L'
5 THEN a.f4
6 ELSE a.f1
7 END = CASE
8 WHEN a.f3 = 'L'
9 THEN b.f4
10 ELSE b.f1
11 END
12 AND CASE
13 WHEN a.f3 = 'L'
14 THEN a.f5
15 ELSE a.f2
16 END = CASE
17 WHEN a.f3 = 'L'
18 THEN b.f5
19 ELSE b.f2
20 END
21 /
F1 F2 F F4 F5 F1 F2 F F4 F5
R1 abc L A1 B1 R3 qwe L A1 B1
R2 lkj L A2 B2 R2 lkj L A2 B2
R3 qwe M A3 B3 R3 qwe L A1 B1
R4 123 M A4 B4 R4 123 M A3 B3
4 rows selected.Regards,
Jo
Edited by: Joice John on Jul 17, 2009 4:30 AM
Sigh!!! Sean you are too fast for me.... ;) -
JDBC to IDOC Scenario - select data in jdbc based on multiple conditions
Hello
I have a JDBC to IDOC Scenario. I have to select the records in JDBC based on different conditions each time. For example I have to select based on company code '1000' and Employee claasification 'E1' and date range. After I post these records in SAP again I want to select other records for some other company code '2000' and different business area and different dates. Basically I want to extract data multiple times based on different conditions.
Hiow do I achieve this?
Another question is in the JDBC to IDOC scenario since the sender adapter is JDBC and the sender adapter polls depending on the duration of time ( say 60 secs ) in the adapter once after I extract the data based on a condition how do I control in such a way that the same data is not extracted again.
Thanks
NagaHi Naga,
I have to select the records in JDBC based on different conditions each time. For example I have to select based on company code '1000' and Employee claasification 'E1' and date range. After I post these records in SAP again I want to select other records for some other company code '2000' and different business area and different dates. Basically I want to extract data multiple times based on different conditions.
-->
Such requirements cant be handle through select query of the sender...but you can handle this in the message mapping area.....you can fire a select query in the database to pick up records in a batch of 10K (do not keep any condition on this except for sorting). After the records come into PI you can send the message to your target based on the unique combination of "Company code+ Employee clasification + date range" handling this in the message mapping.
Another question is in the JDBC to IDOC scenario since the sender adapter is JDBC and the sender adapter polls depending on the duration of time ( say 60 secs ) in the adapter once after I extract the data based on a condition how do I control in such a way that the same data is not extracted again.
You can use the N--> C logic
The data records that you pick have a corresponding control table i assume. There should be a field STATUS where the initial status of record should be N.
After you pick the records this status should be made C so that only those records present in the database with status = N are picked up.
Mention the condition Status = N in the select query.
Thanks
Dhwani
Maybe you are looking for
-
PDF file gets open with blank page behind in IE7
Hi , We have recently upgraded the IE from IE6 to IE7 version. Now when we are tring to open the PDF file ,it opens in Adobe Acrobat reader leaving the blank page in the behind. Bur earlier i.e. in IE6 we were able to open the PDF in the browser itse
-
Dear all, I am trying to upload Word File to the system (ECC6) using transaction OAOR and the system is not behaved as standard. My steps: 1. I created an object in table BDS_LOCL using transaction 'SBDSV1'. 2. Object name created ' ZQMCRED
-
SAP PPPI-MES Z characteristic question
I have a requirement to create some z characteristics to be send to our MES system through control recipe/process order. Those Z characteristics are pretty simple, for example I need to read a field in MARA for the header material, read duration of a
-
HP LaserJet 4000- having memory error...NOT printing.
I am using Windows XP Professional, IE8. Having issues with printing forms, printer used to print the forms perfectly. Any assistance is greatly appreciated. TIA.
-
Hi. I have created a custom material class in reference to class type '001'. This class contains four characteristics. I have created material view "Classification" inserting my material class and i have indicated values in specific characteristics.