Query to conbine 2 lines from table
Hi all
I have a problem in constructing sql query to combine 2 lines from table in Oracle 11g database.
I will explain, i have one table containing call transactions loaded in one table from 2 different sources, one is from IN which is tagged IN and the other from MSC which is tagged MSC. One subscriber call is registered in IN and MSC and loaded in the table. The problem is the data from IN contains the call duration but not contains Cell information. I'm creating datamart to combine the two lines in one lines but i don't know how to do from query.
Here is an overview if my data:
Source Orig Dest startdate cellid duration
MSC 550000 220000 15/05/2012 02:03:29 235e
IN 550000 220000 15/05/2012 02:03:30 10
MSC 550000 220000 15/05/2012 02:04:00 235e
IN 550000 220000 15/05/2012 02:03:59 15
MSC 550000 220001 15/05/2012 02:06:18 235f
IN 550000 220001 15/05/2012 02:06:18 60
The line i want to have is for each line of IN source i sjhould have the cellid like below:
IN 550000 220000 15/05/2012 02:03:30 235e 10
IN 550000 220000 15/05/2012 02:03:59 235e 15
IN 550000 220001 15/05/2012 02:06:18 235f 60
The query should linked by Orig, Dest and date but for some rows there are difference in seconds.
Please help.
Lucienot.
user13513449 wrote:
Hi
Thanks for the reply, here below the create table script and some insert data example:
CREATE TABLE TRANS
CALLTRANSTYPE NVARCHAR2(6),
ORIGANI NVARCHAR2(40),
TERMANI NVARCHAR2(40),
STARTTIME DATE,
STOPTIME DATE,
CELLID NVARCHAR2(10),
CONNECTSECONDS NUMBER,
SWITCHCALLCHARGE NUMBER
0 555283806 222591626 05/15/2012 00:10:04 05/15/2012 00:13:31 03e9:7565 O 207.00
Insert into trans values('MSG','555283806','222591626',to_date('05/15/2012 00:10:04','mm/dd/yyyy hh24:mi:ss'),to_date('05/15/2012 00:13:31','mm/dd/yyyy hh24:mi:ss'),'03e9:7565',10,null); ...It looks like there's some mistake at the end of the CREATE TABLE statement and before the first INSERT statement. Is that supposed to be another INSERT statement?
Test your code and, if necessary, correct it before you post it.
Is that sample data supposed to produce the results you posted originally?
If so, explain, step by step, ho9w you get them.
If not, post the results you want from that smaple data, formatted, between \ tags, as explained in the forum FAQ {message:id=9360002}
In my orioginal message, I said "ORDER BY" where I meant "GROUP BY". If you change that, and use your new table and column names, does the query I posted earlier do what you want? If not, point out where it is wrong, and show how you might get the right results in those places.
Similar Messages
-
SQL Query to fetch records from tables which have 75+ million records
Hi,
I have the explain plan for a sql stmt.Require your suggestions to improve this.
PLAN_TABLE_OUTPUT
| Id | Operation | Name | Rows | Bytes | Cost |
| 0 | SELECT STATEMENT | | 340 | 175K| 19075 |
| 1 | TEMP TABLE TRANSFORMATION | | | | |
| 2 | LOAD AS SELECT | | | | |
| 3 | SORT GROUP BY | | 32M| 1183M| 799K|
| 4 | TABLE ACCESS FULL | CLM_DETAIL_PRESTG | 135M| 4911M| 464K|
| 5 | LOAD AS SELECT | | | | |
| 6 | TABLE ACCESS FULL | CLM_HEADER_PRESTG | 1 | 274 | 246K|
PLAN_TABLE_OUTPUT
| 7 | LOAD AS SELECT | | | | |
| 8 | SORT UNIQUE | | 744K| 85M| 8100 |
| 9 | TABLE ACCESS FULL | DAILY_PROV_PRESTG | 744K| 85M| 1007 |
| 10 | UNION-ALL | | | | |
| 11 | SORT UNIQUE | | 177 | 97350 | 9539 |
| 12 | HASH JOIN | | 177 | 97350 | 9538 |
| 13 | HASH JOIN OUTER | | 3 | 1518 | 9533 |
| 14 | HASH JOIN | | 1 | 391 | 8966 |
| 15 | TABLE ACCESS BY INDEX ROWID | CLM_DETAIL_PRESTG | 1 | 27 | 3 |
| 16 | NESTED LOOPS | | 1 | 361 | 10 |
| 17 | NESTED LOOPS OUTER | | 1 | 334 | 7 |
PLAN_TABLE_OUTPUT
| 18 | NESTED LOOPS OUTER | | 1 | 291 | 4 |
| 19 | VIEW | | 1 | 259 | 2 |
| 20 | TABLE ACCESS FULL | SYS_TEMP_0FD9D66C9_DA2D01AD | 1 | 269 | 2 |
| 21 | INDEX RANGE SCAN | CLM_PAYMNT_CLMEXT_PRESTG_IDX | 1 | 32 | 2 |
| 22 | TABLE ACCESS BY INDEX ROWID| CLM_PAYMNT_CHKEXT_PRESTG | 1 | 43 | 3 |
| 23 | INDEX RANGE SCAN | CLM_PAYMNT_CHKEXT_PRESTG_IDX | 1 | | 2 |
| 24 | INDEX RANGE SCAN | CLM_DETAIL_PRESTG_IDX | 6 | | 2 |
| 25 | VIEW | | 32M| 934M| 8235 |
| 26 | TABLE ACCESS FULL | SYS_TEMP_0FD9D66C8_DA2D01AD | 32M| 934M| 8235 |
| 27 | VIEW | | 744K| 81M| 550 |
| 28 | TABLE ACCESS FULL | SYS_TEMP_0FD9D66CA_DA2D01AD | 744K| 81M| 550 |
PLAN_TABLE_OUTPUT
| 29 | TABLE ACCESS FULL | CCP_MBRSHP_XREF | 5288 | 227K| 5 |
| 30 | SORT UNIQUE | | 163 | 82804 | 9536 |
| 31 | HASH JOIN | | 163 | 82804 | 9535 |
| 32 | HASH JOIN OUTER | | 3 | 1437 | 9530 |
| 33 | HASH JOIN | | 1 | 364 | 8963 |
| 34 | NESTED LOOPS OUTER | | 1 | 334 | 7 |
| 35 | NESTED LOOPS OUTER | | 1 | 291 | 4 |
| 36 | VIEW | | 1 | 259 | 2 |
| 37 | TABLE ACCESS FULL | SYS_TEMP_0FD9D66C9_DA2D01AD | 1 | 269 | 2 |
| 38 | INDEX RANGE SCAN | CLM_PAYMNT_CLMEXT_PRESTG_IDX | 1 | 32 | 2 |
| 39 | TABLE ACCESS BY INDEX ROWID | CLM_PAYMNT_CHKEXT_PRESTG | 1 | 43 | 3 |
PLAN_TABLE_OUTPUT
| 40 | INDEX RANGE SCAN | CLM_PAYMNT_CHKEXT_PRESTG_IDX | 1 | | 2 |
| 41 | VIEW | | 32M| 934M| 8235 |
| 42 | TABLE ACCESS FULL | SYS_TEMP_0FD9D66C8_DA2D01AD | 32M| 934M| 8235 |
| 43 | VIEW | | 744K| 81M| 550 |
| 44 | TABLE ACCESS FULL | SYS_TEMP_0FD9D66CA_DA2D01AD | 744K| 81M| 550 |
| 45 | TABLE ACCESS FULL | CCP_MBRSHP_XREF | 5288 | 149K| 5 |
The CLM_DETAIL_PRESTG table has 100 million records and the CLM_HEADER_PRESTG table has 75 million records.
Any gussestions on how to getch huge records from tables of this size will help.
Regards,
NarayanWITH CLAIM_DTL
AS ( SELECT
ICN_NUM,
MIN (FIRST_SRVC_DT) AS FIRST_SRVC_DT,
MAX (LAST_SRVC_DT) AS LAST_SRVC_DT,
MIN (PLC_OF_SRVC_CD) AS PLC_OF_SRVC_CD
FROM CCP_STG.CLM_DETAIL_PRESTG CD WHERE ACT_CD <>'D'
GROUP BY ICN_NUM),
CLAIM_HDR
AS (SELECT
ICN_NUM,
SBCR_ID,
MBR_ID,
MBR_FIRST_NAME,
MBR_MI,
MBR_LAST_NAME,
MBR_BIRTH_DATE,
GENDER_TYPE_CD,
SBCR_RLTNSHP_TYPE_CD,
SBCR_FIRST_NAME,
SBCR_MI,
SBCR_LAST_NAME,
SBCR_ADDR_LINE_1,
SBCR_ADDR_LINE2,
SBCR_ADDR_CITY,
SBCR_ADDR_STATE,
SBCR_ZIP_CD,
PRVDR_NUM,
CLM_PRCSSD_DT,
CLM_TYPE_CLASS_CD,
AUTHO_NUM,
TOT_BILLED_AMT,
HCFA_DRG_TYPE_CD,
FCLTY_ADMIT_DT,
ADMIT_TYPE,
DSCHRG_STATUS_CD,
FILE_BILLING_NPI,
CLAIM_LOCATION_CD,
CLM_RELATED_ICN_1,
SBCR_ID||0
|| MBR_ID
|| GENDER_TYPE_CD
|| SBCR_RLTNSHP_TYPE_CD
|| MBR_BIRTH_DATE
AS MBR_ENROLL_ID,
SUBSCR_INSGRP_NM ,
CAC,
PRVDR_PTNT_ACC_ID,
BILL_TYPE,
PAYEE_ASSGN_CODE,
CREAT_RUN_CYC_EXEC_SK,
PRESTG_INSRT_DT
FROM CCP_STG.CLM_HEADER_PRESTG P WHERE ACT_CD <>'D' AND SUBSTR(CLM_PRCSS_TYPE_CD,4,1) NOT IN ('1','2','3','4','5','6') ),
PROV AS ( SELECT DISTINCT
PROV_ID,
PROV_FST_NM,
PROV_MD_NM,
PROV_LST_NM,
PROV_BILL_ADR1,
PROV_BILL_CITY,
PROV_BILL_STATE,
PROV_BILL_ZIP,
CASE WHEN PROV_SEC_ID_QL='E' THEN PROV_SEC_ID
ELSE NULL
END AS PROV_SEC_ID,
PROV_ADR1,
PROV_CITY,
PROV_STATE,
PROV_ZIP
FROM CCP_STG.DAILY_PROV_PRESTG),
MBR_XREF AS (SELECT SUBSTR(MBR_ENROLL_ID,1,17)||DECODE ((SUBSTR(MBR_ENROLL_ID,18,1)),'E','1','S','2','D','3')||SUBSTR(MBR_ENROLL_ID,19) AS MBR_ENROLLL_ID,
NEW_MBR_FLG
FROM CCP_STG.CCP_MBRSHP_XREF)
SELECT DISTINCT CLAIM_HDR.ICN_NUM AS ICN_NUM,
CLAIM_HDR.SBCR_ID AS SBCR_ID,
CLAIM_HDR.MBR_ID AS MBR_ID,
CLAIM_HDR.MBR_FIRST_NAME AS MBR_FIRST_NAME,
CLAIM_HDR.MBR_MI AS MBR_MI,
CLAIM_HDR.MBR_LAST_NAME AS MBR_LAST_NAME,
CLAIM_HDR.MBR_BIRTH_DATE AS MBR_BIRTH_DATE,
CLAIM_HDR.GENDER_TYPE_CD AS GENDER_TYPE_CD,
CLAIM_HDR.SBCR_RLTNSHP_TYPE_CD AS SBCR_RLTNSHP_TYPE_CD,
CLAIM_HDR.SBCR_FIRST_NAME AS SBCR_FIRST_NAME,
CLAIM_HDR.SBCR_MI AS SBCR_MI,
CLAIM_HDR.SBCR_LAST_NAME AS SBCR_LAST_NAME,
CLAIM_HDR.SBCR_ADDR_LINE_1 AS SBCR_ADDR_LINE_1,
CLAIM_HDR.SBCR_ADDR_LINE2 AS SBCR_ADDR_LINE2,
CLAIM_HDR.SBCR_ADDR_CITY AS SBCR_ADDR_CITY,
CLAIM_HDR.SBCR_ADDR_STATE AS SBCR_ADDR_STATE,
CLAIM_HDR.SBCR_ZIP_CD AS SBCR_ZIP_CD,
CLAIM_HDR.PRVDR_NUM AS PRVDR_NUM,
CLAIM_HDR.CLM_PRCSSD_DT AS CLM_PRCSSD_DT,
CLAIM_HDR.CLM_TYPE_CLASS_CD AS CLM_TYPE_CLASS_CD,
CLAIM_HDR.AUTHO_NUM AS AUTHO_NUM,
CLAIM_HDR.TOT_BILLED_AMT AS TOT_BILLED_AMT,
CLAIM_HDR.HCFA_DRG_TYPE_CD AS HCFA_DRG_TYPE_CD,
CLAIM_HDR.FCLTY_ADMIT_DT AS FCLTY_ADMIT_DT,
CLAIM_HDR.ADMIT_TYPE AS ADMIT_TYPE,
CLAIM_HDR.DSCHRG_STATUS_CD AS DSCHRG_STATUS_CD,
CLAIM_HDR.FILE_BILLING_NPI AS FILE_BILLING_NPI,
CLAIM_HDR.CLAIM_LOCATION_CD AS CLAIM_LOCATION_CD,
CLAIM_HDR.CLM_RELATED_ICN_1 AS CLM_RELATED_ICN_1,
CLAIM_HDR.SUBSCR_INSGRP_NM,
CLAIM_HDR.CAC,
CLAIM_HDR.PRVDR_PTNT_ACC_ID,
CLAIM_HDR.BILL_TYPE,
CLAIM_DTL.FIRST_SRVC_DT AS FIRST_SRVC_DT,
CLAIM_DTL.LAST_SRVC_DT AS LAST_SRVC_DT,
CLAIM_DTL.PLC_OF_SRVC_CD AS PLC_OF_SRVC_CD,
PROV.PROV_LST_NM AS BILL_PROV_LST_NM,
PROV.PROV_FST_NM AS BILL_PROV_FST_NM,
PROV.PROV_MD_NM AS BILL_PROV_MID_NM,
PROV.PROV_BILL_ADR1 AS BILL_PROV_ADDR1,
PROV.PROV_BILL_CITY AS BILL_PROV_CITY,
PROV.PROV_BILL_STATE AS BILL_PROV_STATE,
PROV.PROV_BILL_ZIP AS BILL_PROV_ZIP,
PROV.PROV_SEC_ID AS BILL_PROV_EIN,
PROV.PROV_ID AS SERV_FAC_ID ,
PROV.PROV_ADR1 AS SERV_FAC_ADDR1 ,
PROV.PROV_CITY AS SERV_FAC_CITY ,
PROV.PROV_STATE AS SERV_FAC_STATE ,
PROV.PROV_ZIP AS SERV_FAC_ZIP ,
CHK_PAYMNT.CLM_PMT_PAYEE_ADDR_LINE_1,
CHK_PAYMNT.CLM_PMT_PAYEE_ADDR_LINE_2,
CHK_PAYMNT.CLM_PMT_PAYEE_CITY,
CHK_PAYMNT.CLM_PMT_PAYEE_STATE_CD,
CHK_PAYMNT.CLM_PMT_PAYEE_POSTAL_CD,
CLAIM_HDR.CREAT_RUN_CYC_EXEC_SK
FROM CLAIM_DTL,(select * FROM CCP_STG.CLM_DETAIL_PRESTG WHERE ACT_CD <>'D') CLM_DETAIL_PRESTG, CLAIM_HDR,CCP_STG.MBR_XREF,PROV,CCP_STG.CLM_PAYMNT_CLMEXT_PRESTG CLM_PAYMNT,CCP_STG.CLM_PAYMNT_CHKEXT_PRESTG CHK_PAYMNT
WHERE
CLAIM_HDR.ICN_NUM = CLM_DETAIL_PRESTG.ICN_NUM
AND CLAIM_HDR.ICN_NUM = CLAIM_DTL.ICN_NUM
AND CLAIM_HDR.ICN_NUM=CLM_PAYMNT.ICN_NUM(+)
AND CLM_PAYMNT.CLM_PMT_CHCK_ACCT=CHK_PAYMNT.CLM_PMT_CHCK_ACCT
AND CLM_PAYMNT.CLM_PMT_CHCK_NUM=CHK_PAYMNT.CLM_PMT_CHCK_NUM
AND CLAIM_HDR.MBR_ENROLL_ID = MBR_XREF.MBR_ENROLLL_ID
AND CLM_DETAIL_PRESTG.FIRST_SRVC_DT >= 20110101
AND MBR_XREF.NEW_MBR_FLG = 'Y'
AND PROV.PROV_ID(+)=SUBSTR(CLAIM_HDR.PRVDR_NUM,6)
AND MOD(SUBSTR(CLAIM_HDR.ICN_NUM,14,2),2)=0
UNION ALL
SELECT DISTINCT CLAIM_HDR.ICN_NUM AS ICN_NUM,
CLAIM_HDR.SBCR_ID AS SBCR_ID,
CLAIM_HDR.MBR_ID AS MBR_ID,
CLAIM_HDR.MBR_FIRST_NAME AS MBR_FIRST_NAME,
CLAIM_HDR.MBR_MI AS MBR_MI,
CLAIM_HDR.MBR_LAST_NAME AS MBR_LAST_NAME,
CLAIM_HDR.MBR_BIRTH_DATE AS MBR_BIRTH_DATE,
CLAIM_HDR.GENDER_TYPE_CD AS GENDER_TYPE_CD,
CLAIM_HDR.SBCR_RLTNSHP_TYPE_CD AS SBCR_RLTNSHP_TYPE_CD,
CLAIM_HDR.SBCR_FIRST_NAME AS SBCR_FIRST_NAME,
CLAIM_HDR.SBCR_MI AS SBCR_MI,
CLAIM_HDR.SBCR_LAST_NAME AS SBCR_LAST_NAME,
CLAIM_HDR.SBCR_ADDR_LINE_1 AS SBCR_ADDR_LINE_1,
CLAIM_HDR.SBCR_ADDR_LINE2 AS SBCR_ADDR_LINE2,
CLAIM_HDR.SBCR_ADDR_CITY AS SBCR_ADDR_CITY,
CLAIM_HDR.SBCR_ADDR_STATE AS SBCR_ADDR_STATE,
CLAIM_HDR.SBCR_ZIP_CD AS SBCR_ZIP_CD,
CLAIM_HDR.PRVDR_NUM AS PRVDR_NUM,
CLAIM_HDR.CLM_PRCSSD_DT AS CLM_PRCSSD_DT,
CLAIM_HDR.CLM_TYPE_CLASS_CD AS CLM_TYPE_CLASS_CD,
CLAIM_HDR.AUTHO_NUM AS AUTHO_NUM,
CLAIM_HDR.TOT_BILLED_AMT AS TOT_BILLED_AMT,
CLAIM_HDR.HCFA_DRG_TYPE_CD AS HCFA_DRG_TYPE_CD,
CLAIM_HDR.FCLTY_ADMIT_DT AS FCLTY_ADMIT_DT,
CLAIM_HDR.ADMIT_TYPE AS ADMIT_TYPE,
CLAIM_HDR.DSCHRG_STATUS_CD AS DSCHRG_STATUS_CD,
CLAIM_HDR.FILE_BILLING_NPI AS FILE_BILLING_NPI,
CLAIM_HDR.CLAIM_LOCATION_CD AS CLAIM_LOCATION_CD,
CLAIM_HDR.CLM_RELATED_ICN_1 AS CLM_RELATED_ICN_1,
CLAIM_HDR.SUBSCR_INSGRP_NM,
CLAIM_HDR.CAC,
CLAIM_HDR.PRVDR_PTNT_ACC_ID,
CLAIM_HDR.BILL_TYPE,
CLAIM_DTL.FIRST_SRVC_DT AS FIRST_SRVC_DT,
CLAIM_DTL.LAST_SRVC_DT AS LAST_SRVC_DT,
CLAIM_DTL.PLC_OF_SRVC_CD AS PLC_OF_SRVC_CD,
PROV.PROV_LST_NM AS BILL_PROV_LST_NM,
PROV.PROV_FST_NM AS BILL_PROV_FST_NM,
PROV.PROV_MD_NM AS BILL_PROV_MID_NM,
PROV.PROV_BILL_ADR1 AS BILL_PROV_ADDR1,
PROV.PROV_BILL_CITY AS BILL_PROV_CITY,
PROV.PROV_BILL_STATE AS BILL_PROV_STATE,
PROV.PROV_BILL_ZIP AS BILL_PROV_ZIP,
PROV.PROV_SEC_ID AS BILL_PROV_EIN,
PROV.PROV_ID AS SERV_FAC_ID ,
PROV.PROV_ADR1 AS SERV_FAC_ADDR1 ,
PROV.PROV_CITY AS SERV_FAC_CITY ,
PROV.PROV_STATE AS SERV_FAC_STATE ,
PROV.PROV_ZIP AS SERV_FAC_ZIP ,
CHK_PAYMNT.CLM_PMT_PAYEE_ADDR_LINE_1,
CHK_PAYMNT.CLM_PMT_PAYEE_ADDR_LINE_2,
CHK_PAYMNT.CLM_PMT_PAYEE_CITY,
CHK_PAYMNT.CLM_PMT_PAYEE_STATE_CD,
CHK_PAYMNT.CLM_PMT_PAYEE_POSTAL_CD,
CLAIM_HDR.CREAT_RUN_CYC_EXEC_SK
FROM CLAIM_DTL, CLAIM_HDR,MBR_XREF,PROV,CCP_STG.CLM_PAYMNT_CLMEXT_PRESTG CLM_PAYMNT,CCP_STG.CLM_PAYMNT_CHKEXT_PRESTG CHK_PAYMNT
WHERE CLAIM_HDR.ICN_NUM = CLAIM_DTL.ICN_NUM
AND CLAIM_HDR.ICN_NUM=CLM_PAYMNT.ICN_NUM(+)
AND CLM_PAYMNT.CLM_PMT_CHCK_ACCT=CHK_PAYMNT.CLM_PMT_CHCK_ACCT
AND CLM_PAYMNT.CLM_PMT_CHCK_NUM=CHK_PAYMNT.CLM_PMT_CHCK_NUM
AND CLAIM_HDR.MBR_ENROLL_ID = MBR_XREF.MBR_ENROLLL_ID
-- AND TRUNC(CLAIM_HDR.PRESTG_INSRT_DT) = TRUNC(SYSDATE)
AND CLAIM_HDR.CREAT_RUN_CYC_EXEC_SK = 123638.000000000000000
AND MBR_XREF.NEW_MBR_FLG = 'N'
AND PROV.PROV_ID(+)=SUBSTR(CLAIM_HDR.PRVDR_NUM,6)
AND MOD(SUBSTR(CLAIM_HDR.ICN_NUM,14,2),2)=0; -
How to Edit Key Fields or Delete Lines from Table Entries
Hi Experts
While releasing Transport Request Number we are getting an error during release. This seems to be as a result of improper data feed while running of eCATT's . The dates in the all these fields have been entered as " . .0101" which is in the wrong format ( eg. Table T811F u2013u201CSDATEu201D field). "SDATE" seems to the key field of the table . Can you please guide on how we may delete these lines or edit the field in the table.
Regards
AnandaHello,
I dont think its a good idea to delete the records from those standard tables. You rather re-run your ecatt and edit/update the existing records and try.
regds,
Kiran -
Please let me know how to write the Query to fetch data from tables
Hi Folks,
Please let me know how to get the data from different tables using the functionality SQ03,SQ02 and SQ01 .
Helpful answers will points awarded.
Regards,
Ram.Dear Ram,
Please find the below link which gives in detail with screen shots.
[SAP Query|http://media.techtarget.com/searchSAP/downloads/Teach_yourself_SAP_C20.pdf#search=%22CREATE%20REPORT%20USING%20SQVI%20%2C%20SAP%22]
Thanks
Murtuza -
Join query not getting data from tables
I have total 4 tables, zemployee, zemp_comm,zemp_adress, zemp_edu1 all of this tables are connected through emp_id , but when I write left outer join it returns all rows but emp_id is retrunign null , when I insert all of the entries in respective table it show the respective emp_id, when i left some of the entries in table it will not show emp_id in records,
I am using this select statment........
Select * from zemployee as a left outer join zemp_comm as b on b~emp_id = a~emp_id left outer join zemp_adress
as c on c~emp_id = a~emp_id left outer join zemp_education1 as d on d~emp_id = a~emp_id into corresponding fields of table
emp_itb
where a~emp_name = zemployee-emp_name.
I want to show show records with emp_id whether i put entry in all tables or missed some of the entries.
please help me in this regard.Hi Amir,
You can use Inner join . please refer below code.
Select * from zemployee as a inner join zemp_comm as b on b~emp_id = a~emp_id inner join zemp_adress
as c on c~emp_id = a~emp_id inner join zemp_education1 as d on d~emp_id = a~emp_id into corresponding fields of table
emp_itb
where a~emp_name = zemployee-emp_name.
Regards,
Thangam.P -
Hi,
I'm creating an ad hoc query to retrieve data from table PPDIT by filtering the transaction key. This is to get a list of amounts posted to the technical accounts(Transaction key HRA). However, the query output and the output from table PPDIT through SE16 are different. It seems like the query only picks up transaction key HRF. Anyone with any ideas why?Hi,
Than you add the additional field from extras option.
click on extras tab.
From there add table add field add structure.
If you want to add a field write the name of the field and continue.
suppose the field is matnr.
Long text = material number
header = material number
and in like reference = mara-matnr.
tablename-field name.
let me know if this helps you.
Regrds,
Nikhil. -
Query to return list of all missing primary key ids from table T1
I found this query online that returns a start and stop for a range of all missing primary key id values from table T1. However i want to rewrite this query to return a whole list of all the missing primary key ids and not a start and stop range. any help plz?
select strt, stp
from (select m.id + 1 as strt,
(select min(id) - 1 from T1 x where x.id > m.id) as stp
from T1 m left outer join T1 r on m.id = r.id - 1 where r.id is null)x where stp is not nullwith t as
select 1 as id from dual union all
select 2 as id from dual union all
select 3 as id from dual union all
select 5 as id from dual union all
select 8 as id from dual union all
select 10 as id from dual union all
select 11 as id from dual union all
select 20 as id from dual
select id_start + level missing_id
from (
select id id_start,
nullif(lead(id) over(order by id) - 1, id) id_end
from t
start with id_end is not null
connect by prior id_start = id_start
and prior dbms_random.random is not null
and level <= id_end - id_start
MISSING_ID
4
6
7
9
12
13
14
15
16
17
18
MISSING_ID
19
12 rows selected.Or:
with t as
select 1 as id from dual union all
select 2 as id from dual union all
select 3 as id from dual union all
select 5 as id from dual union all
select 8 as id from dual union all
select 10 as id from dual union all
select 11 as id from dual union all
select 20 as id from dual
select id_start + level - 1 missing_id
from (
select min(id) id_start,
max(id) id_end
from t
connect by level <= id_end - id_start
minus
select id
from t
MISSING_ID
4
6
7
9
12
13
14
15
16
17
18
MISSING_ID
19
12 rows selected.SY. -
Help with query to return results from group within table?
Hi
Im a total noob, so please be gentle....!
I am looking at a table that has a WORD column and a WORD_TYPE_ID column.
Words can have the same type_id.
What I am trying to do is write a query that will return the longest word for each word_type_id.
I have been trying for hours to get this and all I seem to get is either error messages or I return the longest word in the whole WORD column.
The furthest I can get before things break down is.....
select word
from table
where
length(word) =
select
max(length(word))
from table
Any help on this or if I could be pointed in the right direction it would be greatly appreciated.
ThanksHi,
Welcome to the forum!
Here's one way:
SELECT word_type_id
, MIN (word) KEEP (DENSE_RANK LAST ORDDER BY LENGTH (word)) AS longest_word
FROM table_x
GROUP BY word_type_id;If there happens to be a tie within some word_type_id (that is, 2 or more words have exactly the same length, which is the longest in that group) the expression above will return the first one, in alphabetic order. (That's what MIN means here.)
Edited by: Frank Kulash on Aug 11, 2009 1:56 PM
You almost had it.
As you noticed, you were getting the longest row in the whole table. That's because your sub-query was looking at the whole table.
If you correlate the sub-query to the row in the main table, as shown below, you can get the longest word in each group:
select word
from table m -- m for main
where length (word) = (
select max (length(word))
from table
where word_type_id = m.word_type_id -- New
); -
How To delete the Chosen line from the Table Control
Hi Friends,
i am new to Module Pool Programming , i developed a Table Control in input mode and i am getting data also into that table control. my requirement is that i want to delete the current chosen line from that table control. please help me out.HI
GOOD
GO THROUGH THIS REPORT
REPORT demo_dynpro_tabcont_loop_at.
CONTROLS flights TYPE TABLEVIEW USING SCREEN 100.
DATA: cols LIKE LINE OF flights-cols,
lines TYPE i.
DATA: ok_code TYPE sy-ucomm,
save_ok TYPE sy-ucomm.
DATA: itab TYPE TABLE OF demo_conn.
TABLES demo_conn.
SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE itab.
LOOP AT flights-cols INTO cols WHERE index GT 2.
cols-screen-input = '0'.
MODIFY flights-cols FROM cols INDEX sy-tabix.
ENDLOOP.
CALL SCREEN 100.
MODULE status_0100 OUTPUT.
SET PF-STATUS 'SCREEN_100'.
DESCRIBE TABLE itab LINES lines.
flights-lines = lines.
ENDMODULE.
MODULE cancel INPUT.
LEAVE PROGRAM.
ENDMODULE.
MODULE read_table_control INPUT.
MODIFY itab FROM demo_conn INDEX flights-current_line.
ENDMODULE.
MODULE user_command_0100 INPUT.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'TOGGLE'.
LOOP AT flights-cols INTO cols WHERE index GT 2.
IF cols-screen-input = '0'.
cols-screen-input = '1'.
ELSEIF cols-screen-input = '1'.
cols-screen-input = '0'.
ENDIF.
MODIFY flights-cols FROM cols INDEX sy-tabix.
ENDLOOP.
WHEN 'SORT_UP'.
READ TABLE flights-cols INTO cols WITH KEY selected = 'X'.
IF sy-subrc = 0.
SORT itab STABLE BY (cols-screen-name+10) ASCENDING.
cols-selected = ' '.
MODIFY flights-cols FROM cols INDEX sy-tabix.
ENDIF.
WHEN 'SORT_DOWN'.
READ TABLE flights-cols INTO cols WITH KEY selected = 'X'.
IF sy-subrc = 0.
SORT itab STABLE BY (cols-screen-name+10) DESCENDING.
cols-selected = ' '.
MODIFY flights-cols FROM cols INDEX sy-tabix.
ENDIF.
WHEN 'DELETE'.
READ TABLE flights-cols INTO cols
WITH KEY screen-input = '1'.
IF sy-subrc = 0.
LOOP AT itab INTO demo_conn WHERE mark = 'X'.
DELETE itab.
ENDLOOP.
ENDIF.
ENDCASE.
ENDMODULE.
CHANGE THE CODE AS PER THIS LIGIC.
THANKS
MRUTYUN -
How to select LAST line from a SAP table?
Hi developers,
I need to select the last line from a SAP table, NOT from an internal table.
Something like
SELECT SINGLE LAST FROM pa00169..
any help is more than welcome.Javier,
Based on this statement from you:
"i created a Z table, its a config table that stores some bussines rules, and an id counter, so in order to update that counter i need the last line of the ztable."
I have one additional solution which is the "text box" approach IF the 'id counter' mentioned above is a numeric data type.
If so, use an SQL function to get the highest value of ID_COUNTER.
Then simply add one to it to produce a new, unique, higher-order primary key.
See below:
data: l_id_counter like ztable-id_counter.
data: new_id_counter like ztable-id_counter.
select max( ID_COUNTER ) from ztable into l_id_counter.
new_id_counter = l_i_counter + 1.
Now new_id_counter will be the unique, primary key IF this is the only field in ZTABLE's primary key.
This will also GUARANTEE that your new record is built correctly. -
SAP Query - Additional field that collects information from table RESB
Hello gurus. I have a question.
I want to create a SAP Query that shows me the stock level of a list of materials, and also show me the total quantity of order reservations in an additional field.
I created an InfoSet with table MARD, which is the one that holds the Stock information in a plant. Then I created an additional field which would read information from table RESB, the table that holds order reservations per material.
So I wrote this piece of code:
SELECT * FROM RESB
WHERE MATNR EQ MARD-MATNR and
WERKS EQ MARD-WERKS.
ENDSELECT.
if ( sy-dbcnt NE '0').
MOVE RESB-BDMNG to ZQTY.
ELSE.
MOVE '' to ZQTY.
ENDIF.
This works fine. However, this is currently just catching the first record in table RESB that matches my condition.
What I would like is to collect every instance of RESB-BDMNG and add them to field "ZQTY", have it loop in RESB until it finishes finding every record that match the MATNR and WERKS. With this I could get the total number of order reservations that this material has in that table.
Could someone share some coding that would help me achieve this?Yes! That did it. That's what I needed to do. Thank you so much.
While I'm at it, let me ask you a related question.
When I execute the query, in the first records of the query where there's no value from RESB to transfer, the value of field ZQTY appears empty. Once it finds the first record in RESB and it populates ZQTY with a value, then the rest of the records with no hit get the proper value of 0.
Do you know why the first records in the query appear empty and not with a 0? Is there anything I should add to the coding to fix this? -
Select query based on joining of tables from different database is taking too long
Hi Team,
Select query on table with millions of records is taking very long time. It took 50mins, the below query is joining on multiple table from two databases DB1.dbo.Table1 contains 100 million records and also Table3 and Table4 (of different database) might
contain close to 1million records.
Select T1.*
From DB1.dbo.Table1 T1
Join DB1.dbo.Table2 T2 on RTRIM(T1.Col3) = RTRIM(T2.Col3)
Join Table4 CA on RTRIM(T1.Col1) + T2.Col2 = CA.Col1
Join Table3 U on CA.Col2 = U.Col2 AND RTRIM(T2.Col2) = U.Col3
Where U.Col4 NOT IN ('A1', 'A2', 'A3', 'A4', 'A5', 'A6','A7','A8','A9')
And (T1.flg IS NULL OR T1.flg = 'N')
And LTRIM(RTRIM(T2.Col2)) NOT IN ('B1','B2')
How can i improve the performance of this query. Actual thing is update the data in Db1.dbo.table1 based on the conditions but if the select is taking close to 1hr then update will take hours together. Indexes already implemented on all the tables.
Thanks,
Eshwar.
Please don't forget to Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful. It will helpful to other users.Thanks.
Join Table4 CA on RTRIM(T1.Col1) + T2.Col2 = CA.Col1
This join is not working with spaces if Rtrim is not used.
Thanks! Eshwar.
Please don't forget to Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful. It will helpful to other users. -
Delete lines from iternal table
Hi All!
The problem what I'm having is I have to delete
all the entries from the internal table which are
lets say equal 'XXXXXX'
regards
sas
data lt_itab type standard table of IS_PDATFU.
data wa_itab type IS_PDATFU.
data: lt_roles type BAPIBUS1006_BPROLES occurs 0 with header line,
lt_return type standard table of BAPIRET2,
lv_partner type BU_PARTNER.
lt_itab[] = l_pdatfu_tab[].
LOOP AT lt_itab into wa_itab.
CALL FUNCTION 'BUPA_ROLES_GET_2'
EXPORTING
IV_PARTNER = wa_itab-IPPERS 'PersID
IV_PARTNER_GUID =
IV_DATE = SY-DATLO
TABLES
ET_PARTNERROLES = lt_roles
ET_RETURN = lt_return.
IF lt_roles-PARTNERROLE EQ 'XXXXXX'.
delete this lines from lt_itab[] ????
ENDIF.
ENDLOOP.So u need to use DELETE ITAB:
LOOP AT lt_itab into wa_itab.
CALL FUNCTION 'BUPA_ROLES_GET_2'
EXPORTING
IV_PARTNER = wa_itab-IPPERS 'PersID
IV_PARTNER_GUID =
IV_DATE = SY-DATLO
TABLES
ET_PARTNERROLES = lt_roles
ET_RETURN = lt_return.
IF lt_roles-PARTNERROLE EQ 'XXXXXX'.
delete lt_itab.
ENDIF.
ENDLOOP.
Max
Edited by: max bianchi on Feb 12, 2008 6:17 PM -
Trouble writing Query for Pivoting data from a table
I am having a little trouble writing a query for converting the below table data into a pivot data. I am trying to write a query for which if I give a single valid report_week date as input it should give me the data for that week and also provide two extra columns, one which gives the data of last week for the same countries and the second column which gives the difference of numbers in both the columns(i.e. COUNT - COUNT_LAST_WEEK).
REPORT_WEEK DIVISION COUNT
9/26/2009 country1 81
9/26/2009 country2 97
9/26/2009 country3 12
9/26/2009 country4 26
9/26/2009 country5 101
10/3/2009 country1 85
10/3/2009 country2 98
10/3/2009 country3 10
10/3/2009 country4 24
10/3/2009 country5 101
10/10/2009 country1 84
10/10/2009 country2 98
10/10/2009 country3 10
10/10/2009 country4 25
10/10/2009 country5 102
For example, if I give input as 10/10/2009, the output should be as give below.
REPORT_WEEK DIVISION COUNT COUNT_LAST_WEEK DIFFERENCE
10/10/2009 country1 84 85 -1
10/10/2009 country2 98 98 0
10/10/2009 country3 10 10 0
10/10/2009 country4 25 24 1
10/10/2009 country5 102 101 1
For example, if I give input as 10/3/2009, the output should be as give below.
REPORT_WEEK DIVISION COUNT COUNT_LAST_WEEK DIFFERENCE
10/3/2009 country1 85 81 4
10/3/2009 country2 98 97 1
10/3/2009 country3 10 12 -2
10/3/2009 country4 24 26 -2
10/3/2009 country5 101 101 0
Can anyone please shed some light on Query building for the above scenarios.
Thank you
SKP
Edited by: user11343284 on Oct 10, 2009 7:53 AM
Edited by: user11343284 on Oct 10, 2009 8:28 AMI assume there is no gap in report weeks. If so:
SQL> variable report_week varchar2(10)
SQL> exec :report_week := '10/10/2009'
PL/SQL procedure successfully completed.
with t as (
select to_date('9/26/2009','mm/dd/yyyy') report_week,'country1' division,81 cnt from dual union all
select to_date('9/26/2009','mm/dd/yyyy'),'country2',97 from dual union all
select to_date('9/26/2009','mm/dd/yyyy'),'country3',12 from dual union all
select to_date('9/26/2009','mm/dd/yyyy'),'country4',26 from dual union all
select to_date('9/26/2009','mm/dd/yyyy'),'country5',101 from dual union all
select to_date('10/3/2009','mm/dd/yyyy'),'country1',85 from dual union all
select to_date('10/3/2009','mm/dd/yyyy'),'country2',98 from dual union all
select to_date('10/3/2009','mm/dd/yyyy'),'country3',10 from dual union all
select to_date('10/3/2009','mm/dd/yyyy'),'country4',24 from dual union all
select to_date('10/3/2009','mm/dd/yyyy'),'country5',101 from dual union all
select to_date('10/10/2009','mm/dd/yyyy'),'country1',84 from dual union all
select to_date('10/10/2009','mm/dd/yyyy'),'country2',98 from dual union all
select to_date('10/10/2009','mm/dd/yyyy'),'country3',10 from dual union all
select to_date('10/10/2009','mm/dd/yyyy'),'country4',25 from dual union all
select to_date('10/10/2009','mm/dd/yyyy'),'country5',102 from dual
select max(report_week) report_week,
division,
max(cnt) keep(dense_rank last order by report_week) cnt_this_week,
max(cnt) keep(dense_rank first order by report_week) cnt_last_week,
max(cnt) keep(dense_rank last order by report_week) - max(cnt) keep(dense_rank first order by report_week) difference
from t
where report_week in (to_date(:report_week,'mm/dd/yyyy'),to_date(:report_week,'mm/dd/yyyy') - 7)
group by division
order by division
REPORT_WE DIVISION CNT_THIS_WEEK CNT_LAST_WEEK DIFFERENCE
10-OCT-09 country1 84 85 -1
10-OCT-09 country2 98 98 0
10-OCT-09 country3 10 10 0
10-OCT-09 country4 25 24 1
10-OCT-09 country5 102 101 1
SQL> exec :report_week := '10/3/2009'
PL/SQL procedure successfully completed.
SQL> /
REPORT_WE DIVISION CNT_THIS_WEEK CNT_LAST_WEEK DIFFERENCE
03-OCT-09 country1 85 81 4
03-OCT-09 country2 98 97 1
03-OCT-09 country3 10 12 -2
03-OCT-09 country4 24 26 -2
03-OCT-09 country5 101 101 0
SQL> SY. -
How to export a reference to a table line from a method?
Hello,
I have a class which has a hashed table as an attribute. I want to retrieve a line from the table using the key and return a reference to the table line. I want changes to the return value of the method to be directly reflected in the table, as if using a local field symbol. I have tried to approaches, neither of which works.
First, I returned a reference to the local field symbol. This dumps, because after returning from the method call, the target of this reference no longer resides on the stack.
Second, I have tried using an export parameter marked as "pass by reference", i. e. without VALUE(). Strangely, this still seems to give me only a copy of the data.
What is the correct way to proceed?
Illustrative pseudo-code follows.
Thanks, Sebastian
*==============================================================
*Possibility 1: (using references)
DATA mt_key_map TYPE zt_entity. " member variable (hash table of zs_entity)
METHODS get
IMPORTING
!is_key TYPE zs_key
EXPORTING
!er_vt TYPE REF TO zs_entity.
METHOD get.
FIELD-SYMBOLS: <fs_vt> TYPE zs_entity.
READ TABLE mt_key_value WITH KEY key = is_key ASSIGNING <fs_vt>.
GET REFERENCE OF <fs_vt> INTO er_vt.
ENDMETHOD.
" Client Code:
FIELD-SYMBOLS: <fs_vt> TYPE zs_entity.
CALL METHOD get
EXPORTING
is_key = is_key
IMPORTING
er_vt = lr_vt.
ASSIGN lr_vt->* TO <fs_vt>. " will dump, because the local field symbol
" to which lr_vt points is no longer on the stack
<fs_vt>-value = 'newdata'.
*==============================================================
*Possibility 2: (using a structure passed by reference)
DATA mt_key_map TYPE zt_entity. " member variable (hash table of zs_entity)
METHODS get
IMPORTING
!is_key TYPE zs_key
EXPORTING
!es_vt TYPE zs_entity.
METHOD get.
FIELD-SYMBOLS: <fs_vt> TYPE zs_entity.
READ TABLE mt_key_map WITH KEY key = is_key ASSIGNING <fs_vt>.
es_vt = <fs_vt>.
ENDMETHOD.
" Client Code:
DATA: ls_vt TYPE zs_entity.
CALL METHOD get
EXPORTING
is_key = is_key
IMPORTING
es_vt = ls_vt.
ls_vt-value = 'newdata'. " will not change the contents of the
" table mt_key_valueIn the first approch, try to change the exporting parameter type REF TO DATA.
Try like:
CLASS lcl_test DEFINITION.
PUBLIC SECTION.
DATA: t_mara TYPE HASHED TABLE OF mara WITH UNIQUE KEY matnr.
METHODS:
constructor,
get
IMPORTING
if_matnr TYPE matnr
EXPORTING
ea_mara TYPE REF TO data.
ENDCLASS. "lcl_test DEFINITION
START-OF-SELECTION.
DATA: lo_test TYPE REF TO lcl_test,
lr_data TYPE REF TO data.
FIELD-SYMBOLS: <fa_mara> TYPE ANY,
<f_field> TYPE ANY.
CREATE OBJECT lo_test.
lo_test->get(
EXPORTING
if_matnr = '000000000077000000' " << Replace Your Material
IMPORTING
ea_mara = lr_data ).
ASSIGN lr_data->* TO <fa_mara>.
ASSIGN COMPONENT 'ERSDA' OF STRUCTURE <fa_mara> TO <f_field>.
<f_field> = space.
WRITE: 'Done'.
CLASS lcl_test IMPLEMENTATION.
METHOD constructor.
SELECT * INTO TABLE t_mara
FROM mara
UP TO 10 ROWS.
ENDMETHOD. "constructor
METHOD get.
FIELD-SYMBOLS: <lfs_mara> LIKE LINE OF me->t_mara.
READ TABLE me->t_mara ASSIGNING <lfs_mara> WITH KEY matnr = if_matnr.
GET REFERENCE OF <lfs_mara> INTO ea_mara.
ENDMETHOD. "get
ENDCLASS. "lcl_test IMPLEMENTATION
Regards,
Naimesh Patel
Maybe you are looking for
-
Hi. So yesterday, my iPhone 4S got stolen while I was in PE class. Immediately after I realized that it was gone, I called my dad and he cancelled the service for me (Verizon) so that the person who stole it would not be able to use it. I've been che
-
Stereo audio export showing as mono
Hi, I've been encountering an issue with exporting stereo audio from Premiere CS6 (v. 6.0.5) and After Effects CS6 (11.0.2.11). When I export a clip with stereo audio from Premiere or After Effects (usually to ProRes or Uncompressed QuickTime), the r
-
<FONT face=Century size=2>Do you think I can be able to connect my MP3 Player (Zen Micro) via USB 2.0 Cable to the PS2? Cause maybe it'll play the music.
-
Whenever I launch the automated aspect for making web pages of photographs CS2 crashes. I have used this before using Tiger but with Leopard now it is a non performer. Any ideas
-
G4 has SuperDrive CD/DVD player/recorder. Was able to watch a DVD movie when I first got laptop (about a month ago), but don't remember what application I used. Now, system can't seem to find the player. 1) When I search Finder help, I get a link for