SQL Query to retrieve one line from duplicate records
Hi
I have one table which contains duplicate records in multiple column but the difference is in one column which contains the value 0 or positive. The query i want is to retrieve only the line with the positive value for only the duplicated records.
here below a sample data for your reference:
CREATE TABLE TRANS
CALLTRANSTYPE NVARCHAR2(6),
ORIGANI NVARCHAR2(40),
TERMANI NVARCHAR2(40),
STARTTIME DATE,
STOPTIME DATE,
CELLID NVARCHAR2(10),
CONNECTSECONDS NUMBER,
SWITCHCALLCHARGE NUMBER
INSERT INTO TRANS VALUES ('REC','555988801','222242850',to_date('05/15/2012 09:15:00','mm/dd/yyyy hh24:mi:ss'),to_date('05/15/2012 09:15:25','mm/dd/yyyy hh24:mi:ss'),null,25,0)
INSERT INTO TRANS VALUES ('REC','555988801','222242850',to_date('05/15/2012 09:15:00','mm/dd/yyyy hh24:mi:ss'),to_date('05/15/2012 09:15:25','mm/dd/yyyy hh24:mi:ss'),null,25,18000)
INSERT INTO TRANS VALUES ('REC','555988801','222242850',to_date('05/15/2012 09:18:03','mm/dd/yyyy hh24:mi:ss'),to_date('05/15/2012 09:18:20','mm/dd/yyyy hh24:mi:ss'),null,17,0)
The output i want to have is:
CALLTRANSTYPE ORIGANI TERMANI STARTTIME STOPTIME CELLID CONNECTSECONDS SWITCHCALLCHARGE
REC 555988801 222242850 05/15/2012 09:15:00 05/15/2012 09:15:25 25 18000
REC 555988801 222242850 05/15/2012 09:18:03 05/15/2012 09:18:20 17 0 Thank you.
Hi ekh
this is the query i want to have, thank you for the help:
SQL> Select *from
select CALLTRANSTYPE,ORIGANI,TERMANI,STARTTIME,STOPTIME,CELLID,CONNECTSECONDS,SWITCHCALLCHARGE
,row_number() over( partition by STARTTIME ,STOPTIME order by SWITCHCALLCHARGE DESC ) rn from TRANS
where rn=1;
CALLTR ORIGANI TERMANI STARTTIME STOPTIME CELLID CONNECTSECONDS SWITCHCALLCHARGE RN
REC 555988801 222242850 15-MAY-12 15-MAY-12 25 18000 1
REC 555988801 222242850 15-MAY-12 15-MAY-12 17 0 1Regrads
Lucienot.
Similar Messages
-
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. -
SQL query to retrieve totals from "supporting Details"
We've had a strange issue where the totals from the supporting details aren't adding up to the value submitted in essbase.
In effect our RDMS is out of sync with Planning.
In order to remedy this, I'm trying to build a SQL query to retrieve the value of the supporting details.
Here is my Sql statement so far :
SELECT
HO1.OBJECT_NAME SCENARIO,
HO2.OBJECT_NAME ACCOUNT,
HO3.OBJECT_NAME ENTITY,
HO4.OBJECT_NAME Month,
HO5.OBJECT_NAME Version,
HO6.OBJECT_NAME Currency,
HO7.OBJECT_NAME Year,
HO8.OBJECT_NAME Project,
HO10.OBJECT_NAME CC,
HO12.OBJECT_NAME Grplcl,
HO13.OBJECT_NAME Product,
HO15.OBJECT_NAME SalesRegion,
HO16.OBJECT_NAME ContractAnalysis,
HO17.OBJECT_NAME IC,
SUM(NVL(HCDI.VALUE,0)) AMOUNT
FROM hsp_column_detail HCD,
hsp_column_detail_ITEM HCDI,
HSP_OBJECT HO1,
HSP_OBJECT HO2,
HSP_OBJECT HO3,
HSP_OBJECT HO4,
HSP_OBJECT HO5,
HSP_OBJECT HO6,
HSP_OBJECT HO7,
HSP_OBJECT HO8,
HSP_OBJECT HO10,
HSP_OBJECT HO12,
HSP_OBJECT HO13,
HSP_OBJECT HO15,
HSP_OBJECT HO16,
HSP_OBJECT HO17
WHERE hcd.detail_id = hcdi.detail_id
AND hcd.dim1 = ho1.object_id
AND hcd.dim2 = ho2.object_id
AND hcd.dim3 = ho3.object_id
AND hcd.dim4 = ho4.object_id
AND hcd.dim5 = ho5.object_id
AND hcd.dim6 = ho6.object_id
AND hcd.dim7 = ho7.object_id
AND hcd.dim8 = ho8.object_id
AND hcd.dim10 = ho10.object_id
AND hcd.dim12 = ho12.object_id
AND hcd.dim13 = ho13.object_id
AND hcd.dim15 = ho15.object_id
AND hcd.dim16 = ho16.object_id
AND hcd.dim17 = ho17.object_id
and hcdi.generation = 0
GROUP BY HO1.OBJECT_NAME, HO2.OBJECT_NAME, HO3.OBJECT_NAME, HO4.OBJECT_NAME,
HO5.OBJECT_NAME,
HO6.OBJECT_NAME,
HO7.OBJECT_NAME,
HO8.OBJECT_NAME,
HO10.OBJECT_NAME,
HO12.OBJECT_NAME,
HO13.OBJECT_NAME,
HO15.OBJECT_NAME,
HO16.OBJECT_NAME,
HO17.OBJECT_NAME
ORDER BY HO1.OBJECT_NAME, HO3.OBJECT_NAME, HO2.OBJECT_NAMEThis query works using PL SQL and has been used on Oracle 9.2.3.
Cheers,
Jeremie
Here is the Query:
set serveroutput on;
set serveroutput on size 1000000;
--set buffer_size 10000000;
--set line_size 2000;
--DBMS_OUTPUT.size = 2000000;
DECLARE
CURSOR BUDGET_HEADERS_CU IS
SELECT
hcd.detail_id,
HO1.OBJECT_NAME SCENARIO,
HO2.OBJECT_NAME ACCOUNT,
HO3.OBJECT_NAME ENTITY,
HO4.OBJECT_NAME Month,
HO5.OBJECT_NAME Version,
HO6.OBJECT_NAME Currency,
HO7.OBJECT_NAME Year,
HO8.OBJECT_NAME Project,
HO10.OBJECT_NAME CC,
HO12.OBJECT_NAME Grplcl,
HO13.OBJECT_NAME Product,
HO15.OBJECT_NAME SalesRegion,
HO16.OBJECT_NAME ContractAnalysis,
HO17.OBJECT_NAME IC,
hcd.dim1 SCENARIO_id,
hcd.dim2 ACCOUNT_id,
hcd.dim3 ENTITY_id,
hcd.dim4 Month_id,
hcd.dim5 Version_id,
hcd.dim6 Currency_ID,
hcd.dim7 Year_ID,
hcd.dim8 Project_ID,
hcd.dim10 CC_ID,
hcd.dim12 Grplcl_ID,
hcd.dim13 Product_ID,
hcd.dim15 SalesRegion_ID,
hcd.dim16 ContractAnalysis_ID,
hcd.dim17 IC_ID
FROM hsp_column_detail HCD, /*hsp_column_detail_item HCDi,*/
HSP_OBJECT HO1,
HSP_OBJECT HO2,
HSP_OBJECT HO3,
HSP_OBJECT HO4,
HSP_OBJECT HO5,
HSP_OBJECT HO6,
HSP_OBJECT HO7,
HSP_OBJECT HO8,
HSP_OBJECT HO10,
HSP_OBJECT HO12,
HSP_OBJECT HO13,
HSP_OBJECT HO15,
HSP_OBJECT HO16,
HSP_OBJECT HO17
WHERE /*hcd.detail_id = hcdi.detail_id
AND*/ hcd.dim1 = ho1.object_id
AND hcd.dim2 = ho2.object_id
AND hcd.dim3 = ho3.object_id
AND hcd.dim4 = ho4.object_id
AND hcd.dim5 = ho5.object_id
AND hcd.dim6 = ho6.object_id
AND hcd.dim7 = ho7.object_id
AND hcd.dim8 = ho8.object_id
AND hcd.dim10 = ho10.object_id
AND hcd.dim12 = ho12.object_id
AND hcd.dim13 = ho13.object_id
AND hcd.dim15 = ho15.object_id
AND hcd.dim16 = ho16.object_id
AND hcd.dim17 = ho17.object_id
and HO5.OBJECT_NAME = 'Working'
--and hcdi.generation != 0
--and hcdi.label like 'JRTEST-%'
--and hcd.detail_id = 253102
/*GROUP BY HCD.Dim1, HCD.Dim2, HCD.Dim3, HCD.Dim4,
HCD.Dim5,
HCD.Dim6,
HCD.Dim7,
HCD.Dim8,
HCD.Dim10,
HCD.Dim12,
HCD.Dim13,
HCD.Dim15,
HCD.Dim16,
HCD.Dim17*/;
CURSOR BUDGET_DETAILS_CU(
/*scenario_p in varchar2,
account_p in varchar2,
entity_p in varchar2,
month_p in varchar2,
version_p in varchar2,
currency_p in varchar2,
year_p in varchar2,
project_p in varchar2,
cc_p in varchar2,
grplcl_p in varchar2,
product_p in varchar2,
salesregion_p in varchar2,
contractanalysis_p in varchar2,
ic_p in varchar2*/
detail_id_p in number
IS
SELECT
/* HO1.OBJECT_NAME SCENARIO,
HO2.OBJECT_NAME ACCOUNT,
HO3.OBJECT_NAME ENTITY,
HO4.OBJECT_NAME Month,
HO5.OBJECT_NAME Version,
HO6.OBJECT_NAME Currency,
HO7.OBJECT_NAME Year,
HO8.OBJECT_NAME Project,
HO10.OBJECT_NAME CC,
HO12.OBJECT_NAME Grplcl,
HO13.OBJECT_NAME Product,
HO15.OBJECT_NAME SalesRegion,
HO16.OBJECT_NAME ContractAnalysis,
HO17.OBJECT_NAME IC, */
label,
NVL(HCDI.VALUE,0) AMOUNT,
HCDI.Position,
HCDI.operator,
HCDI.generation
FROM /*hsp_column_detail HCD,*/
hsp_column_detail_ITEM HCDI
/* HSP_OBJECT HO1,
HSP_OBJECT HO2,
HSP_OBJECT HO3,
HSP_OBJECT HO4,
HSP_OBJECT HO5,
HSP_OBJECT HO6,
HSP_OBJECT HO7,
HSP_OBJECT HO8,
HSP_OBJECT HO10,
HSP_OBJECT HO12,
HSP_OBJECT HO13,
HSP_OBJECT HO15,
HSP_OBJECT HO16,
HSP_OBJECT HO17*/
--WHERE hcd.detail_id = hcdi.detail_id
WHERE hcdi.detail_id = detail_id_p
/*AND hcd.dim1 = ho1.object_id
AND hcd.dim2 = ho2.object_id
AND hcd.dim3 = ho3.object_id
AND hcd.dim4 = ho4.object_id
AND hcd.dim5 = ho5.object_id
AND hcd.dim6 = ho6.object_id
AND hcd.dim7 = ho7.object_id
AND hcd.dim8 = ho8.object_id
AND hcd.dim10 = ho10.object_id
AND hcd.dim12 = ho12.object_id
AND hcd.dim13 = ho13.object_id
AND hcd.dim15 = ho15.object_id
AND hcd.dim16 = ho16.object_id
AND hcd.dim17 = ho17.object_id*/
--and hcdi.generation != 0
--and label like 'JRTEST-%'
/*AND HCD.Dim1 = scenario_p
AND HCD.Dim2 = account_p
AND HCD.Dim3 = entity_p
AND HCD.Dim4 = month_p
AND HCD.Dim5 = version_p
AND HCD.Dim6 = currency_p
AND HCD.Dim7 = year_p
AND HCD.Dim8 = project_p
AND HCD.Dim10 = cc_p
AND HCD.Dim12 = grplcl_p
AND HCD.Dim13 = product_p
AND HCD.Dim15 = salesregion_p
AND HCD.Dim16 = contractanalysis_p
AND HCD.Dim17 = ic_p*/
ORDER BY hcdi.position;
-- Variable Declaration
running_total_ln number :=0;
prev_running_total_ln number :=0;
add_amount number :=0;
multiply_amount number :=1;
prev_generation number :=0;
prev_add_amount number :=0;
prev_multiply_amount number :=1;
running_total_gen0 number :=0;
running_gen0_op number :=0;
running_total_gen1 number :=0;
running_gen1_op number :=0;
running_total_gen2 number :=0;
running_gen2_op number :=0;
running_total_gen3 number :=0;
running_gen3_op number :=0;
running_total_gen4 number :=0;
running_gen4_op number :=0;
running_total_gen5 number :=0;
running_gen5_op number :=0;
output_file utl_file.file_type;
-- Begin PL/SQL processing
BEGIN
--DBMS_OUTPUT.
DBMS_OUTPUT.ENABLE(1000000);
DBMS_OUTPUT.PUT_LINE('Begin Processing');
output_file := utl_file.fopen ('C:\temp', 'test.txt', 'W');
-- Begin Header For Loop
FOR BUDGET_HEADERS_CV IN BUDGET_HEADERS_CU
LOOP
--Reset Running Totals
running_total_ln:=0;
prev_running_total_ln:=0;
add_amount:=0;
multiply_amount:=1;
prev_generation:=0;
prev_add_amount:=0;
prev_multiply_amount:=1;
running_total_gen0:=0;
running_gen0_op:=0;
running_total_gen1:=0;
running_gen1_op:=0;
running_total_gen2:=0;
running_gen2_op:=0;
running_total_gen3:=0;
running_gen3_op:=0;
running_total_gen4:=0;
running_gen4_op:=0;
running_total_gen5:=0;
running_gen5_op:=0;
-- Begin Detail For Loop
FOR BUDGET_DETAILS_CV IN BUDGET_DETAILS_CU(
BUDGET_HEADERS_CV.Detail_ID
/*BUDGET_HEADERS_CV.SCENARIO_ID,
BUDGET_HEADERS_CV.ACCOUNT_ID,
BUDGET_HEADERS_CV.ENTITY_ID,
BUDGET_HEADERS_CV.Month_ID,
BUDGET_HEADERS_CV.Version_ID,
BUDGET_HEADERS_CV.Currency_ID,
BUDGET_HEADERS_CV.Year_ID,
BUDGET_HEADERS_CV.Project_ID,
BUDGET_HEADERS_CV.CC_ID,
BUDGET_HEADERS_CV.Grplcl_ID,
BUDGET_HEADERS_CV.Product_ID,
BUDGET_HEADERS_CV.SalesRegion_ID,
BUDGET_HEADERS_CV.ContractAnalysis_ID,
BUDGET_HEADERS_CV.IC_ID*/
LOOP
-- Null;
add_amount :=0;
multiply_amount :=1;
IF BUDGET_DETAILS_CV.OPERATOR = 1 THEN
add_amount := BUDGET_DETAILS_CV.Amount;
End if;
IF BUDGET_DETAILS_CV.OPERATOR = 2 THEN
add_amount := BUDGET_DETAILS_CV.Amount * -1;
End if;
IF BUDGET_DETAILS_CV.OPERATOR = 3 THEN
multiply_amount := BUDGET_DETAILS_CV.Amount;
End if;
IF BUDGET_DETAILS_CV.OPERATOR = 4 THEN
multiply_amount := 1/BUDGET_DETAILS_CV.Amount;
End if;
IF BUDGET_DETAILS_CV.Position = 0 then
running_total_gen0 := add_amount*multiply_amount;-- we are dealing with the first line
Else
if BUDGET_DETAILS_CV.GENERATION = prev_generation then
-- run whatever total we are on up
if BUDGET_DETAILS_CV.GENERATION = 0 then
running_total_gen0 := (running_total_gen0 + add_amount)*multiply_amount;
end if;
if BUDGET_DETAILS_CV.GENERATION = 1 then
running_total_gen1 := (running_total_gen1 + add_amount)*multiply_amount;
end if;
if BUDGET_DETAILS_CV.GENERATION = 2 then
running_total_gen2 := (running_total_gen2 + add_amount)*multiply_amount;
end if;
if BUDGET_DETAILS_CV.GENERATION = 3 then
running_total_gen3 := (running_total_gen3 + add_amount)*multiply_amount;
end if;
end if;
if BUDGET_DETAILS_CV.GENERATION = prev_generation +1 then
-- we are going up a generation
-- (we cannot go up to gen0
if BUDGET_DETAILS_CV.GENERATION = 1 then
running_total_gen1:=0;-- reset gen1 counter
running_gen0_op:=BUDGET_DETAILS_CV.OPERATOR; -- Store the sign for later operation
running_total_gen0 := running_total_gen0/prev_multiply_amount - prev_add_amount; -- Remove parent from Gen 0 total
running_total_gen1 := (running_total_gen1 + add_amount)*multiply_amount;
end if;
if BUDGET_DETAILS_CV.GENERATION = 2 then
running_total_gen2:=0;-- reset gen1 counter
running_gen1_op:=BUDGET_DETAILS_CV.OPERATOR; -- Store the sign for later operation
running_total_gen1 := running_total_gen1/prev_multiply_amount - prev_add_amount; -- Remove parent from Gen 1 total
running_total_gen2 := (running_total_gen2 + add_amount)*multiply_amount;
end if;
if BUDGET_DETAILS_CV.GENERATION = 3 then
running_total_gen3:=0;-- reset gen1 counter
running_gen2_op:=BUDGET_DETAILS_CV.OPERATOR; -- Store the sign for later operation
running_total_gen2 := running_total_gen2/prev_multiply_amount - prev_add_amount; -- Remove parent from Gen 2 total
running_total_gen3 := (running_total_gen3 + add_amount)*multiply_amount;
end if;
end if;
if BUDGET_DETAILS_CV.GENERATION = prev_generation - 1 then
-- we are Down a generation
if BUDGET_DETAILS_CV.GENERATION = 0 then
--we need to "add" back the previous gen 1 parent
IF running_gen0_op = 1 THEN
running_total_gen0 := running_total_gen0 + running_total_gen1;
End if;
IF running_gen0_op = 2 THEN
running_total_gen0 := running_total_gen0 - running_total_gen1;
End if;
IF running_gen0_op = 3 THEN
running_total_gen0 := running_total_gen0 * running_total_gen1;
End if;
IF running_gen0_op = 4 THEN
running_total_gen0 := running_total_gen0 / running_total_gen1;
End if;
-- we need to add the current member to the gen0
running_total_gen0 := (running_total_gen0 + add_amount)*multiply_amount;
END IF;
if BUDGET_DETAILS_CV.GENERATION = 1 then
--we need to "add" back the previous gen 2 parent
IF running_gen1_op = 1 THEN
running_total_gen1 := running_total_gen1 + running_total_gen2;
End if;
IF running_gen1_op = 2 THEN
running_total_gen1 := running_total_gen1 - running_total_gen2;
End if;
IF running_gen1_op = 3 THEN
running_total_gen1 := running_total_gen1 * running_total_gen2;
End if;
IF running_gen1_op = 4 THEN
running_total_gen1 := running_total_gen1 / running_total_gen2;
End if;
-- we need to add the current member to the gen1
running_total_gen1 := (running_total_gen1 + add_amount)*multiply_amount;
end if;
if BUDGET_DETAILS_CV.GENERATION = 2 then
--we need to "add" back the previous gen 3 parent
IF running_gen1_op = 1 THEN
running_total_gen2 := running_total_gen2 + running_total_gen3;
End if;
IF running_gen1_op = 2 THEN
running_total_gen2 := running_total_gen2 - running_total_gen3;
End if;
IF running_gen1_op = 3 THEN
running_total_gen2 := running_total_gen2 * running_total_gen3;
End if;
IF running_gen1_op = 4 THEN
running_total_gen2 := running_total_gen2 / running_total_gen3;
End if;
-- we need to add the current member to the gen2
running_total_gen2 := (running_total_gen2 + add_amount)*multiply_amount;
end if;
end if;
if BUDGET_DETAILS_CV.GENERATION = prev_generation - 2 then
-- we are Down 2 generations
if BUDGET_DETAILS_CV.GENERATION = 0 then
--we need to "add" back the previous gen 2 parent
IF running_gen1_op = 1 THEN
running_total_gen1 := running_total_gen1 + running_total_gen2;
End if;
IF running_gen1_op = 2 THEN
running_total_gen1 := running_total_gen1 - running_total_gen2;
End if;
IF running_gen1_op = 3 THEN
running_total_gen1 := running_total_gen1 * running_total_gen2;
End if;
IF running_gen1_op = 4 THEN
running_total_gen1 := running_total_gen1 / running_total_gen2;
End if;
--we need to "add" back the previous gen 1 parent
IF running_gen0_op = 1 THEN
running_total_gen0 := running_total_gen0 + running_total_gen1;
End if;
IF running_gen0_op = 2 THEN
running_total_gen0 := running_total_gen0 - running_total_gen1;
End if;
IF running_gen0_op = 3 THEN
running_total_gen0 := running_total_gen0 * running_total_gen1;
End if;
IF running_gen0_op = 4 THEN
running_total_gen0 := running_total_gen0 / running_total_gen1;
End if;
-- we need to add the current member to the gen0
running_total_gen0 := (running_total_gen0 + add_amount)*multiply_amount;
END IF;
if BUDGET_DETAILS_CV.GENERATION = 1 then
--we need to "add" back the previous gen 3 parent
IF running_gen1_op = 1 THEN
running_total_gen2 := running_total_gen2 + running_total_gen3;
End if;
IF running_gen1_op = 2 THEN
running_total_gen2 := running_total_gen2 - running_total_gen3;
End if;
IF running_gen1_op = 3 THEN
running_total_gen2 := running_total_gen2 * running_total_gen3;
End if;
IF running_gen1_op = 4 THEN
running_total_gen2 := running_total_gen2 / running_total_gen3;
End if;
--we need to "add" back the previous gen 2 parent
IF running_gen1_op = 1 THEN
running_total_gen1 := running_total_gen1 + running_total_gen2;
End if;
IF running_gen1_op = 2 THEN
running_total_gen1 := running_total_gen1 - running_total_gen2;
End if;
IF running_gen1_op = 3 THEN
running_total_gen1 := running_total_gen1 * running_total_gen2;
End if;
IF running_gen1_op = 4 THEN
running_total_gen1 := running_total_gen1 / running_total_gen2;
End if;
-- we need to add the current member to the gen1
running_total_gen1 := (running_total_gen1 + add_amount)*multiply_amount;
END IF;
if BUDGET_DETAILS_CV.GENERATION = prev_generation - 3 then
-- we are Down 3 generations
if BUDGET_DETAILS_CV.GENERATION = 0 then
--we need to "add" back the previous gen 3 parent
IF running_gen1_op = 1 THEN
running_total_gen2 := running_total_gen2 + running_total_gen3;
End if;
IF running_gen1_op = 2 THEN
running_total_gen2 := running_total_gen2 - running_total_gen3;
End if;
IF running_gen1_op = 3 THEN
running_total_gen2 := running_total_gen2 * running_total_gen3;
End if;
IF running_gen1_op = 4 THEN
running_total_gen2 := running_total_gen2 / running_total_gen3;
End if;
--we need to "add" back the previous gen 2 parent
IF running_gen1_op = 1 THEN
running_total_gen1 := running_total_gen1 + running_total_gen2;
End if;
IF running_gen1_op = 2 THEN
running_total_gen1 := running_total_gen1 - running_total_gen2;
End if;
IF running_gen1_op = 3 THEN
running_total_gen1 := running_total_gen1 * running_total_gen2;
End if;
IF running_gen1_op = 4 THEN
running_total_gen1 := running_total_gen1 / running_total_gen2;
End if;
--we need to "add" back the previous gen 1 parent
IF running_gen0_op = 1 THEN
running_total_gen0 := running_total_gen0 + running_total_gen1;
End if;
IF running_gen0_op = 2 THEN
running_total_gen0 := running_total_gen0 - running_total_gen1;
End if;
IF running_gen0_op = 3 THEN
running_total_gen0 := running_total_gen0 * running_total_gen1;
End if;
IF running_gen0_op = 4 THEN
running_total_gen0 := running_total_gen0 / running_total_gen1;
End if;
-- we need to add the current member to the gen0
running_total_gen0 := (running_total_gen0 + add_amount)*multiply_amount;
END IF;
end if;
END IF;
End IF;
END LOOP; -- End of Detail Loop
--DBMS_OUTPUT.PUT_LINE(BUDGET_HEADERS_CV.SCENARIO||';'||BUDGET_HEADERS_CV.ACCOUNT||';'||BUDGET_HEADERS_CV.ENTITY||';'||BUDGET_HEADERS_CV.Month||';'||BUDGET_HEADERS_CV.Version||';'||BUDGET_HEADERS_CV.Currency||';'||BUDGET_HEADERS_CV.Year||';'||BUDGET_HEADERS_CV.Project||';'||BUDGET_HEADERS_CV.CC||';'||BUDGET_HEADERS_CV.Grplcl||';'||BUDGET_HEADERS_CV.Product||';'||BUDGET_HEADERS_CV.SalesRegion||';'||BUDGET_HEADERS_CV.ContractAnalysis||';'||BUDGET_HEADERS_CV.IC||';'||running_total_gen0);
utl_file.put_line(output_file,BUDGET_HEADERS_CV.SCENARIO||';'||BUDGET_HEADERS_CV.ACCOUNT||';'||BUDGET_HEADERS_CV.ENTITY||';'||BUDGET_HEADERS_CV.Month||';'||BUDGET_HEADERS_CV.Version||';'||BUDGET_HEADERS_CV.Currency||';'||BUDGET_HEADERS_CV.Year||';'||BUDGET_HEADERS_CV.Project||';'||BUDGET_HEADERS_CV.CC||';'||BUDGET_HEADERS_CV.Grplcl||';'||BUDGET_HEADERS_CV.Product||';'||BUDGET_HEADERS_CV.SalesRegion||';'||BUDGET_HEADERS_CV.ContractAnalysis||';'||BUDGET_HEADERS_CV.IC||';'||running_total_gen0);
/*BUDGET_HEADERS_CV.SCENARIO, BUDGET_HEADERS_CV.ACCOUNT, BUDGET_HEADERS_CV.ENTITY, BUDGET_HEADERS_CV.Month, BUDGET_HEADERS_CV.Version,BUDGET_HEADERS_CV.Currency, BUDGET_HEADERS_CV.Year, BUDGET_HEADERS_CV.Project, BUDGET_HEADERS_CV.CC, BUDGET_HEADERS_CV.Grplcl, BUDGET_HEADERS_CV.Product, BUDGET_HEADERS_CV.SalesRegion, BUDGET_HEADERS_CV.ContractAnalysis, BUDGET_HEADERS_CV.IC */
END LOOP; -- End of Header Loop
--DBMS_OUTPUT.PUT_LINE('Total');
-- DBMS_OUTPUT.PUT_LINE('End Processing');
utl_file.fclose(output_file);
END;
Edited by: JeremieR on Apr 18, 2011 5:02 AM -
Ad-hoc query - data on one line pr.employee
Hi,
I try to get data on one line from ad-hoc reporting. When I choose to report on several IT0105 subtypes, the subtypes are written out on one line each pr. employee. This does not look good, and is a hazal to our customer since they need to edit the report in excel. I have tried to code the switches "PERSON_ONLY_ONCE" and "LAST_DATA_ONLY" without results. Any hints/tip?
Thank you,
Kind regards
Hildehello hilde,
I think it is not possible to do it with ad-hoc.
you have to use query itself, with creating your own layout.
SQ01
regards
Stefan -
Reading one line from a text file into an array
i want to read one line from a text file into an array, and then the next line into a different array. both arays are type string...i have this:
public static void readAndProcessData(FileInputStream stream){
InputStreamReader iStrReader = new InputStreamReader (stream);
BufferedReader reader = new BufferedReader (iStrReader);
String line = "";
try{
int i = 0;
while (line != null){
names[i] = reader.readLine();
score[i] = reader.readLine();
line = reader.readLine();
i++;
}catch (IOException e){
System.out.println("Error in file access");
this section calls it:
try{
FileInputStream stream = new FileInputStream("ISU.txt");
HighScore.readAndProcessData(stream);
stream.close();
names = HighScore.getNames();
scores = HighScore.getScores();
}catch(IOException e){
System.out.println("Error in accessing file." + e.toString());
it gives me an array index out of bounds erroroh wait I see it when I looked at the original quote.
They array you made called names or the other one is prob too small for the amount of names that you have in the file. Hence as I increases it eventually goes out of bounds of the array so you should probably resize the array if that happens. -
How to notify in case SQL query(JDBC sender adapter) does not fetch records
hi,
How can we notify(by alerts or something) in case SQL query(JDBC sender adapter) does not fetch records? In channels logs it only says processing started & finished(no message is created for same).
Thanks,
MayankHi,
1 ) What is exact audit log message ?
2) Try fetching the count in SQL statement if there are any valid records it will give the count.
May for testing you can use <TEST> in update statement.
3) Have you used taskTimeout parameter ?
4) Are multiple channels polling on same table ?
regards
Ganga -
SQL query to retrieve families with only one generation from a family db
Hi,
I need to write an SQL query that would select families with only one generation ((which means a person - or a married couple - with kids) or (a person - or a married couple - with parents but no kids)) from a database containing families. The simplified db structure is:
person:
id - int, primary key
siblings:
id
parent_id
kid_id
marriage
id:
husband_id
wife_id
Could anyone please help me? I dont really have any idea how to accomplish that...Hi,
Welcome to the forum!
Assuming that siblings (despite its name) contains only parent-child relationships, and that the parent_id could be either the mother or the father:
WITH got_tree AS
SELECT CONNECT_BY_ROOT s.parent_id AS root_id
, LEVEL AS lvl
FROM siblings s
LEFT OUTER JOIN marriage m ON s.parent_id IN ( m.husband_id
, m.wife_id
START WITH parent_id NOT IN ( SELECT kid_id
FROM siblings
CONNECT BY s.parent_id IN ( PRIOR m.husband_id
, PRIOR m.wife_id
, PRIOR kid_id
SELECT root_id
FROM got_tree
GROUP BY root_id
HAVING MAX (lvl) <= 2
;This will get a list of parents who may or may not have children, but who do not have either parents or grandchildren.
To get their spouses and children (if any) you will have to join this result set to all the other tables. At that point, you can eliminate poeple who do not have ancestors themselves, but are married to people who have more than one generation of ancestors.
The details of how to do that depend on the details of your tables. If you'd like help, then post a little sample data (CREATE TABLE and INSERT statements for all tables) and the results you want from that data.
Edited by: Frank Kulash on Oct 14, 2009 4:05 PM
I'd need sample data in order to test this, of course. -
I am using the "fetch all" vi to do this, but it is retrieving one record at a time, (if you examine the block diagram) How can i retrieve all records in a faster more efficient manner?
If this isn't faster than your previous method, then I think you found the wrong example. If you have the Database Connectivity Toolkit installed, then go to the LabVIEW Help menu and select "Find Examples". It defaults to searching for tasks, so open the "Communicating with External Applications" and "Databases" and open the Read All Data. The List Column names just gives the correct header to the resulting table and is a fast operation. That's not what you are supposed to be looking at ... it's the DBTools Select All Data subVI that is the important one. If you open it and look at its diagram, you'll see that it uses a completely different set of ADO methods and properties to retrieve all the data.
-
Hi all,
I've been beating my head against this for a few days now, and while
there is a workaround, I haven't found out what's causing this to
happen.
Every other SQL query except for this one particular query works fine
and returns a scrollable result set. That one query on the other hand,
returns a non-scrollable result set.
Here's the code which is calling the query:
sqlStatement = getSQLFromFile();
debug("SQL statment = " + sqlStatement);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
debug(sqlStatement);
rst = stmt.executeQuery(sqlStatement);
debug("The type is " + rst.getType());
rst.last();
For most queries, the output is "The type is 1004" - which means the
resultset is scrollable - as it should be.
For one particular query, the output is "The type is 1003" which means
that the result set is of type forward-only.
Of course, calling rst.last() fails in the second case.
If the difference between the queries was drastic, I might have
something to go on. I've tested this out with different size queries,
but the switch between having the type incorrectly changed is the
deletion of a 0x0a 0x0d on the first line.
I.E. this means the failing query reads :
"select
from........."
and the query which works reads
"select *
from........."
I've looked at the failing query in it's binary format, and that's the
only difference I can discern.
To further confuse things, there are other queries which have a
similar format - and which work.
I've read about a bug in Weblogic 5.1 SP9 which ignores the setting of
the Statement to return a ResultSet with a scrollable cursor, and
while this seems to be a bug, it doesn't seem the same bug at all -
besides, I'm using Weblogic 6.0 with SP1 on a W2K system.
Does anyone have any ideas as to what might be causing this? I'm
stumped..Ryan D'Silva wrote:
Hi Joe,
I'm using the Oracle thin driver -
oracle.jdbc.driver.OracleDriver - version #8.1.6.0.0
and the DBMS is
"Oracle9i Enterprise Edition Release 9.2.0.2.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.2.0 - Production"
Does that help?Yes. Two things: TYou should probably upgrade the oracle thin
driver, by downloading the latest appropriate one from their site,
and make sure it's ahead of all weblogic jars in the classpath the
server builds for itself. Also, let's see how simple we can make the
problem. Would you please repeat the JDBC that demonstrated the problem,
in a small standalone java program that uses a direct thin driver connection,
getting weblogic out of the picture? (The problem does sound like
and oracle driver issue).
Joe
>
>
Thanks,
- ryan
You don't say what DBMS and what JDBC driver you're using for the pool.
That is likely to be the issue. Let me know.
Joe
Here's the code which is calling the query:
sqlStatement = getSQLFromFile();
debug("SQL statment = " + sqlStatement);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
debug(sqlStatement);
rst = stmt.executeQuery(sqlStatement);
debug("The type is " + rst.getType());
rst.last();
For most queries, the output is "The type is 1004" - which means the
resultset is scrollable - as it should be.
For one particular query, the output is "The type is 1003" which means
that the result set is of type forward-only.
Of course, calling rst.last() fails in the second case.
If the difference between the queries was drastic, I might have
something to go on. I've tested this out with different size queries,
but the switch between having the type incorrectly changed is the
deletion of a 0x0a 0x0d on the first line.
I.E. this means the failing query reads :
"select
from........."
and the query which works reads
"select *
from........."
I've looked at the failing query in it's binary format, and that's the
only difference I can discern.
To further confuse things, there are other queries which have a
similar format - and which work.
I've read about a bug in Weblogic 5.1 SP9 which ignores the setting of
the Statement to return a ResultSet with a scrollable cursor, and
while this seems to be a bug, it doesn't seem the same bug at all -
besides, I'm using Weblogic 6.0 with SP1 on a W2K system.
Does anyone have any ideas as to what might be causing this? I'm
stumped.. -
SQL query to get transaction detail from DEFERRED_TRAN_ID
Hi,
I'm using Oracle Advance Replication and get the transaction detail from Enterprise Manager Console.
So instead of using the console.
Is there a way any SQL query which get transaction details like SQL query fired, old and new column value etc from DEFERRED_TRAN_ID.
thanksquote:
Originally posted by:
lucapac
I have two tables: tblWorkers and tblSkills. tblWorkers has a
column, Skills, which is populated from a multiple-checkbox form
field with one or more skill_IDs from tblSkills, so each
tblWorkers.Skills consists of a list of one or more comma-delimited
values. For any Skill_ID, I need to generate a listing of all
Workers with the corresponding skill, so I have tried to do
something along the lines of SELECT WorkerName FROM tblWorkers
WHERE Skills IN (Skills, #FORM.Skill_ID#) ... or WHERE Skills IN
(ListFind(Skills, #FORM.Skill_ID#)) ... etc. ??? My results (once I
got data type mismatches out of the way) return all Workers, not
just those with the desired Skill. There must be an easy way to do
this ... How do people with a bit more CF/SQL experience than I
have do this???
As Kronin implied, we normalize our databases. If you don't
understand that answer, the book "Database Design for Mere Mortals"
is often mentioned on this forum. -
Need efficient SQL query to retrieve data for MLM website
Table cd_members
MemberID LeftID RightID
1 2 3
2 4 5
3 6 7
4 8 -
5 - -
6 - -
7 - -
8 9 10
9 - -
10 - -
i want to execute a query to retrieve downline of a member say MemberID 2
o/p should be Records with MemberID 4,5,8,9,10
i am using this query but don't know how to start from MembeID=2
select a.memberid, a.tradingid, a.refid, a.parentid, a.node, a.leftid, a.rightid, b.memberid from cd_members a, cd_members b
where (a.leftid=b.memberid or a.rightid=b.memberid)Again, assuming that the number of levels is known, you can just do N self joins (note that I intentionally go one level further than necessary in this case
SQL> ed
Wrote file afiedt.buf
1 with t
2 as
3 (
4 select 1 person, 2 left, 3 right from dual union all
5 select 2, 4, 5 from dual union all
6 select 3, 6, 7 from dual union all
7 select 4, 8, null from dual union all
8 select 5, null, null from dual union all
9 select 6, null, null from dual union all
10 select 7, null, null from dual union all
11 select 8, 9, 10 from dual union all
12 select 9, null, null from dual union all
13 select 10, null, null from dual
14 )
15 select t1.left, t1.right, t2.left, t2.right, t3.left, t3.right, t4.left, t
4.right
16 from t t1,
17 t t2,
18 t t3,
19 t t4
20 where t1.person = 2
21 and t1.left = t2.person(+)
22 and t2.left = t3.person(+)
23* and t3.left = t4.person(+)
SQL> /
LEFT RIGHT LEFT RIGHT LEFT RIGHT LEFT
RIGHT
4 5 8 9 10Justin -
Discoverer Report - SQL Query to retrieve list of parameters
Hi
We have around 100 Discoverer reports and I'm trying to find the list of parameters used in each report.
Is there any SQL query that I can use to find the parameters used for each report
or
should I open the reports one by one to fetch the list of parameters used.
I checked the tables in EUL4_US schema but no luck.
- Amarnath.Kgive this a try for starters. It looks at the custom folders defined in the business area, which is where any LOV's defined for you parameters would be. As far as looking at the workbooks themselves, no, there is no way to do that in sql.
select
decode(eb.ba_created_by,'ORACLE_APPS','Seeded','Custom') Origin,
eb.ba_name business_area,
eo.OBJ_TYPE,
decode(eo.obj_type, 'SOBJ','From Database', 'CUO', 'Custom Query', 'COBJ', 'Complex Folder', eo.obj_type) obj_type_desc,
eo.OBJ_NAME folder,
eo.OBJ_DESCRIPTION folder_description,
decode(eo.sobj_ext_table, NULL, NULL, eo.obj_ext_owner || '.' || eo.sobj_ext_table) base_object,
decode(es.seg_obj_id, null, UPPER(trim(eo.obj_object_sql1)||trim(eo.obj_object_sql2)||trim(eo.obj_object_sql3))
, UPPER(trim(es.seg_chunk1) || trim(es.seg_chunk2) || trim(es.seg_chunk3) || trim(es.seg_chunk4))) SQL
from
eul4_us.EUL5_BAS eb,
eul4_us.EUL5_objs eo,
eul4_us.EUL5_BA_OBJ_LINKS ebol,
eul4_us.eul5_segments es
where
eb.BA_ID = ebol.BOL_BA_ID and
ebol.BOL_OBJ_ID = eo.OBJ_ID and
eo.obj_id = es.seg_obj_id (+) and
decode(eb.ba_created_by,'ORACLE_APPS','Seeded','Custom') = 'Custom'
order by
/*decode(eb.ba_created_by,'ORACLE_APPS','Seeded','Custom'), */eb.ba_name, ebol.BOL_SEQUENCE, es.seg_sequence -
Hi Team,
I am looking for an SQL query to check the data (ECC + CallVariable) received following a RUN SCRIPT RESULT when requesting an external VRU with a Translation Route to VRU with a "Run External Script".
I believe the data are parsed between the Termination Call Detail + Termination Call Variable .
If you already have such an SQL query I would very much appreciate to have it.
Thank you and Regards
NickOmar,
with all due respect, shortening a one day's interval might not be an option for a historical report ;-)
I would recommend to take a look the following SQL query:
DECLARE @dateFrom DATETIME, @dateTo DATETIME
SET @dateFrom = '2014-01-24 00:00:00'
SET @dateTo = '2014-01-25 00:00:00'
SELECT
tcv.DateTime,
tcd.RecoveryKey,
tcd.RouterCallKeyDay,
tcd.RouterCallKey,
ecv.EnterpriseName AS [ECVEnterpriseName],
tcv.ArrayIndex,
tcv.ECCValue
FROM Termination_Call_Variable tcv
JOIN
(SELECT RouterCallKeyDay,RouterCallKey,RecoveryKey FROM Termination_Call_Detail WHERE DateTime > @dateFrom AND DateTime < @dateTo) tcd
ON tcv.TCDRecoveryKey = tcd.RecoveryKey
LEFT OUTER JOIN Expanded_Call_Variable ecv ON tcv.ExpandedCallVariableID = ecv.ExpandedCallVariableID
WHERE tcv.DateTime > @dateFrom AND tcv.DateTime < @dateTo
With variables, you can parametrize your code (for instance, you could write SET @dateFrom = ? and let the calling application fill in the datetime value in for you).
Plus joining two large tables with all rows like you did (TCD-TCV) is never a good option.
Another aspect to consider: all ECC's are actually arrays (always), so it's not good to leave out the index value (tcv.ArrayIndex).
G. -
SQL Query to retrieve the All records based on the Max Dates.
Hello all,
I am trying to retrieve the newest record based on the date field ( nextDate ).
Currently there are only 4 records in the MC_Maintenance table and two in the Machine table.
Machine table
MC_id EquipID
1 0227
MC_id EquipID
2 0228
MC_Maintenance table
Maint_id MC_id Next_maint
1 2 08/25/2010
2 2 07/01/2010
3 1 06/11/2010
4 1 07/11/2010
What I am trying to accomplish is,
list the two machines from the Machine table with the MAX(Next_maint) controlling the MC_Maintenance output list
These are the records that I would like to Display.
Maint_id MC_id Next_maint
1 2 08/25/2010
4 1 07/11/2010
Below is the SQL Query
SELECT
MC.MC_ID as ID,
MC.complete_Date as completed,
MC.next_maint as nextDate,
MC.maint_notes as Notes,
MC.facility as Facility,
M.EquipId,
M.name as name,
M.SerialNumber as SN,
M.dept as dept,
M.Freq as freq
From MC_Maintenance MC, Machine M
where MC.MC_ID = M.MC_ID
' USING MAX(nextDate )
Any ideas would help.
TJI would have thought that was a simple group by problem?
SELECT M.EquipID, MC.MC_ID, Max(MC.next_maint)
FROM MC_Maintenance MC INNER JOIN Machine M ON MC.MC_ID = M.MC_ID
GROUP BY M.EquipID, MC.MC_ID -
MS SQL query to get Subscription list from Operations Manager
Hi Experts,
Is there anyway get Subscription list from Operations Manager DB using SQL query? I lost subscription list, and need to create subscription as it was. Very urgent.
Thanks in advance.
Regards
Karthick MHi,
Hope the powershell command Get-SCOMNotificationSubscription can be helpful for you:
Get-SCOMNotificationSubscription
Retrieves a list of notification subscriptions.
https://technet.microsoft.com/en-us/library/hh918490(v=sc.20).aspx
Regards,
Yan Li
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact [email protected]
Maybe you are looking for
-
I'm not updating to FF5 because I'll lose my GoogleToolBar. What are your plans ?
When I try to update to Firefox 5 (seriously recommended by Mozilla) I receive the message that my GoogleToolBar is not compatible and will be disabled. Such an action will let me lost in the browser. I don't have the option to export it to Chrome, b
-
I think my phone is dead?!
On a normal day my battery will last me all day, run down to about 30-20%, and then I'll charge it up at night. Yesterday I noticed my battery life was down to like 50% at about 1:30pm, which is unusual for my phone considering it was idle while I wa
-
Macbook Pro: How do I set up a RAID system?
Macbook Pro: How do I set up a RAID system on a MACBOOK PRO properly? Can I have the OS on the same drives or does it need to be seperate? I mostly want to do this becuase I am having a lot of problems with the "spinning ball of death" and slow speed
-
Raw material as Traded material
Dear All, I am working for a client which is into manufacturing of Generators. One of the raw material which is used to manufacture the Generators, is also sold to vendor. For FG material, it is Make to Order scenario. For the raw material, its Make
-
hi all, i want to query the partition tables which are more than 1GB in size? how can i query?