Creating Records Based on Joining record
Hi Experts,
I have an requirement
Pernr | Begda| Endda| Wage1|Wage2|Join Date
1
>
IFF wrote:
> Hi Experts,
>
> I have an requirement
>
>
> Pernr | Begda| Endda| Wage1|Wage2|Join Date
> 1
@ Fun
It seems like the question bot encountered an "Program Terminated Dump" while posting the question. See log for further details
Similar Messages
-
Restrict the detail record based on the record indicator
Hi, i have a master detail form
when i query the form at header block it shows all the headers say
header block
header, line num, desc
1, 1, pen
1 ,2, rubber
1 ,3, sketchpen
line block
line num, sub item ,cost
1 ,1.1, 50
1 ,1.2, 60
2 ,2.1, 70
2, 2.2, 5
it shows the output in this way
i want to restrict the line level block (say if my cursor is at record indicating row 1 in header) then in line level it should show
lines pertaining to line num 1 and header 1 --eg pen records
if my cursor is at line num 2 in header block, in line level block it should show only line num 2 details ie rubber details, how can i restrict this.
Thanks,Define the relation between header and detail
join condition : header.line_num = detail.line_num
delete record behaviour : non-isolated
prevent masterless operations : Yes
after this if you navigate, the detail records will automatically gets queried accordingly.
Regards
Dora -
How to create Form based on a table to display multiple record
Hello All,
Would somebody please tell me how to create a Form based on a single table ,
to view and insert multi record based on a single table.In other words I would like
to have a form as shown below ,where the users can Insert,update,delete,query and so on
Item Id PArt Number List Price
100 Item-1 $120.oo
200 Item-2 $150.00
300 Item-3 $50.00
I know I can do it as Single Record block using Tabular Format,but multiple record ?????
Thanks in Anticipation
BabuTry this method,
1. Creat a Master Detail Form (Custom Layout and not tabular)
and in the master block select one field.
2. In the HTML layout for master remove the reference for
that field(so that nothing will appear in the master block
of the form).
3. Before the update (in the Pl/SQL event handler select the 'Save' event and write the following code to avoid updating master block).
p_session.set_value(p_block_name => 'MASTER_BLOCK',
p_attribute_name => 'MASTER_ACTION',
p_value => 'None');
doSave;
For eg, let's say
Master is from 'Dept' table and Detail is from 'Emp' table(with join condition Dept.dept_id = Emp.dept_id). In the master remove everything except dept_id field and in the HTML layout for master remove the reference of the dept_id field(you cannot remove this field physically from the master layout). Now the form will look like multirow form rather than master detail form but only problem with this workaround is 'Detail Action' will be present in the detail block.
I hope this will help you.
Thanks
-Krishnamurthy -
How to create a record based on the name of a file in the file-system?
Hi,
With a lot of pictures I want to have a database to gather some information about these pictures.
First question is how to generate a record based on a file in the file system?
e.g. the pictures are "c:\fotos\2009\01\disc_001.jpg" to "c:\foto\2009\01\dis_98.jpg" .
now i want to create records with as one of the attributes the name of the picture (not the picture itself). how to create these records (based on the information of the file-ssytem). i.e. the number of records should be the same as the number of pictures.
any suggestions?
any reaction will be appreciated.
LeoLink to Create directory
http://www.adp-gmbh.ch/ora/sql/create_directory.html
You can create a list of files in the directory and read the list files from that directory.
[UTL_FILE Documentation |http://download.oracle.com/docs/cd/B14117_01/appdev.101/b10802/u_file.htm#996728]
[Solution using Java|http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:439619916584]
SS -
Best way to create detail records based on data in the master record..
Hi,
I am using 11gr1p1 and ADF stack.
I have a master detail relation between 2 records. I have EO and entity associations. I want to create a number detail records based on the data on the master record.
For example
I have a Stay Record which has begin and end date I need to create the DailyStay Record for each day for the range of begin and end date of StayRecord.
Where should I do this? In EO implementation or in VO implementation.?
ThanksWhere should I do this? In EO implementation or in VO implementation.?If your child record should in no case be created without those default values, then EO.
Otherwise, to increase reusability of your EO, then in the VO over the view link (i.e. other VO's would still be able to use your EO without having the child VO created with these defaults).
This way your ViewObjects can also be used in a context where you don't want to copy from the masterFrank, If there's another UI flow that is so drastically different that it does not want things defaulted, then it probably needs a different VO altogether (on the same underlying EO though) -
Web GUI new feature - creating a new record based on the current record
Vincent,
We need new feature in Web GUI:
creating a new record based on the current record with data
from Moscow with moneyIt is already enabled, in the next release.
If you joint TAB program, the march preview build contains it. User can select 1 or multiple users and make a copy. -
Hi Experts,
Iam doing a Idoc to file scenario.
Based on the sales organization(VKORG),i need to create the multiple records in the file.
For example :
E1MARAM 0..Unbounded
|
|E1MARMM 0..Unbounded
|
E1MARMM
|
E1MARMM
|
E1MARMM
|
E1MVKEM 0..Unbounded
|
E1MVKEM
When E1MVKEM-VKORG = Z200 then i need to create a file with 4 records (for 4 E1MARMM segments 4 records will be created)
When one more E1MVKEM-VKORG = Z201 present then we need to create 4 more records for Z201 in the same file.
So now i will be getting a single file with 8 records.
Each E1MVKEM segment will be having only one VKORG value.
I tried with <b>oneasmany</b> function,but its creating only for VKORG=Z200 with 4 values but its not providing the values for VKORG=Z201.
Please suggest me what to do.. I need to write UDF's or can i achieve without using them.??
PS: we are not using BPM in our scenario.
Thank You.
Regards
Seema.Hi Prabhu,
I need to display the records in the file for each sales organisation (MVKEM-VKORG) .
MARAM is the parent node and MARMM,MVKEM are child nodes.
MARAM
MARMM
MARMM
MARMM
MVKEM
MVKEM
Consider that first MVKEM has VKORG = Z200 then 3 records has to display in file (for 3 MARMM segments 3 records has to display)
Simillarly consider second MVKEM has VKORG = Z201 then 3 more records has to display in file. ( same as above for 3 MARMM segments = 3 records in file)
So for the above structure i will be getting a total of 6 Records in my output file.
Iam trying with different Node functions but it is taking only for first VKORG and not taking the second one.so iam getting only 3 records in my file.
Please help me in cracking this.
Regards
Seema. -
How to omit records based on a status code
I am trying to select records based on a status 'N' or 'A' by a certain date as long as by the chosen date there is not another status given to the same course like 'D' or 'X'.
Here are some sample data...
CREATE TABLE #TEST
(ID VARCHAR(7),
COURSE VARCHAR(10),
CURRENT_STATUS VARCHAR(1),
STATUS_DATE DATETIME)
INSERT INTO #TEST
(ID, COURSE, CURRENT_STATUS, STATUS_DATE)
VALUES
('0020541','AAAA-1000H', 'X', '2013-08-27 00:00:00.000'),
('0020541','AAAA-1000H', 'N', '2013-08-26 00:00:00.000'),
('0020541','BBBB-2000H', 'D', '2013-11-04 00:00:00.000'),
('0020541','BBBB-2000H', 'N', '2013-08-27 00:00:00.000'),
('0020541','CCCC-3000H', 'D', '2013-09-11 00:00:00.000'),
('0020541','CCCC-3000H', 'N', '2013-08-26 00:00:00.000'),
('0020541','DDDD-4000H', 'A', '2013-08-25 00:00:00.000'),
('0020541','EEEE-5000H', 'N', '2013-08-26 00:00:00.000')
SELECT * FROM #TEST
DROP TABLE #TEST
If the query is to determine how many records with a status of N or A up to and incl August 26, 2013, I should see 4 records... AAAA-1000H, CCCC-3000H, DDDD-4000H, EEEE-5000H
If the query is to determine how many records with a status of N or A up to and incl October 1, 2013, I should see 3 records... BBBB-2000H, DDDD-4000H, EEEE-5000H
...and so on.
Any help is appreciated.I am trying to select records based on a status 'N' or 'A' by a certain date as long as by the chosen date there is not another status given to the same course like 'D' or 'X'.
Here are some sample data...
CREATE TABLE #TEST
(ID VARCHAR(7),
COURSE VARCHAR(10),
CURRENT_STATUS VARCHAR(1),
STATUS_DATE DATETIME)
INSERT INTO #TEST
(ID, COURSE, CURRENT_STATUS, STATUS_DATE)
VALUES
('0020541','AAAA-1000H', 'X', '2013-08-27 00:00:00.000'),
('0020541','AAAA-1000H', 'N', '2013-08-26 00:00:00.000'),
('0020541','BBBB-2000H', 'D', '2013-11-04 00:00:00.000'),
('0020541','BBBB-2000H', 'N', '2013-08-27 00:00:00.000'),
('0020541','CCCC-3000H', 'D', '2013-09-11 00:00:00.000'),
('0020541','CCCC-3000H', 'N', '2013-08-26 00:00:00.000'),
('0020541','DDDD-4000H', 'A', '2013-08-25 00:00:00.000'),
('0020541','EEEE-5000H', 'N', '2013-08-26 00:00:00.000')
SELECT * FROM #TEST
DROP TABLE #TEST
If the query is to determine how many records with a status of N or A up to and incl August 26, 2013, I should see 4 records... AAAA-1000H, CCCC-3000H, DDDD-4000H, EEEE-5000H
If the query is to determine how many records with a status of N or A up to and incl October 1, 2013, I should see 3 records... BBBB-2000H, DDDD-4000H, EEEE-5000H
...and so on.
Any help is appreciated.
I guess I didn't understand your problem. Not sure if this might help you.
SELECT * FROM #TEST
where CURRENT_STATUS IN ('N','A') AND STATUS_DATE<='2013-08-26'
AND STATUS_DATE NOT IN(Select STATUS_DATE from #test
where CURRENT_STATUS IN ('D','X'))
SELECT * FROM #TEST
where CURRENT_STATUS IN ('N','A')
AND STATUS_DATE<='2013-10-01'
AND STATUS_DATE NOT IN(Select STATUS_DATE from #test
where CURRENT_STATUS IN ('D','X'))
- please mark correct answers -
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 -
How to add extra per day records based on maximum occurances in the week.
Hello,
I need to add extra records based on maximum occurances on a day in a week.
For example, the result of the query shows that maximum occuances in a week 0 is 3 on so I need to add empty records in each day in that week.
SQL QUERY:
with numbers as (
SELECT ROWNUM N FROM dual
CONNECT BY LEVEL <=35
),months as (
SELECT ADD_MONTHS('01-JUN-10',n-1) AS current_month,
TO_CHAR(ADD_MONTHS('01-JUN-10',n-1),'fmMonth-YYYY') AS current_month_label
FROM numbers
WHERE ADD_MONTHS('01-JUN-10',n-1) <= NVL(add_months('01-JUN-10', :monthcount-1),:p_month)
ORDER BY n ASC
) , dates as (
select trunc(trunc(m.current_month, 'MM'), 'D') + n - 1 calendar_date,
trunc((n - 1) / 7) AS week_num,
m.current_month as current_month
from numbers, months m
where trunc(dom.schedule.calendar_begin(m.current_month) + n - 1, 'd') <= last_day(m.current_month)
Order By week_num, calendar_date
select dates.week_num, edate, name from (
--week 0
select '30-MAY-10' as edate, 'JJ' as name from dual union
select '31-MAY-10' as edate, 'MK' as name from dual union
select '01-JUN-10' as edate, 'MK' as name from dual union
select '01-JUN-10' as edate, 'BK' as name from dual union
select '01-JUN-10' as edate, 'JJ' as name from dual union
select '04-JUN-10' as edate, 'KK' as name from dual union
select '04-JUN-10' as edate, 'LA' as name from dual union
-- week 1
select '06-JUN-10' as edate, 'BK' as name from dual union
select '06-JUN-10' as edate, 'JJ' as name from dual union
select '07-JUN-10' as edate, 'KK' as name from dual union
select '11-JUN-10' as edate, 'LA' as name from dual
) a join dates on dates.calendar_date = a.edate
order by week_num, to_date(edate);CURRENT RESULT :
WEEK_NUM EDATE NAME
0 30-MAY-10 JJ
0 31-MAY-10 MK
0 01-JUN-10 MK
0 01-JUN-10 JJ
0 01-JUN-10 BK
0 04-JUN-10 KK
0 04-JUN-10 LA
1 06-JUN-10 BK
1 06-JUN-10 JJ
1 07-JUN-10 KK
1 11-JUN-10 LAREQUIRED RESULT:
WEEK_NUM EDATE NAME
0 30-MAY-10 JJ
0 30-MAY-10 null
0 30-MAY-10 null
0 31-MAY-10 MK
0 31-MAY-10 null
0 31-MAY-10 null
0 01-JUN-10 BK
0 01-JUN-10 JJ
0 01-JUN-10 MK
0 02-JUN-10 null
0 02-JUN-10 null
0 02-JUN-10 null
0 03-JUN-10 null
0 03-JUN-10 null
0 03-JUN-10 null
0 04-JUN-10 KK
0 04-JUN-10 LA
0 04-JUN-10 null
0 05-JUN-10 null
0 05-JUN-10 null
0 05-JUN-10 null
--Number of Week 1 records should be 14 = (max occurances on 06-JUN-10) * 7
1 06-JUN-10 BK
1 06-JUN-10 JJ
1 07-JUN-10 KK
1 07-JUN-10 null
1 08-JUN-10 null
1 08-JUN-10 null
1 09-JUN-10 null
1 09-JUN-10 null
1 10-JUN-10 null
1 10-JUN-10 null
1 11-JUN-10 LA
1 11-JUN-10 null
1 12-JUN-10 null
1 12-JUN-10 nullI would appreciate it if you could help me to find efficient way to achieve this?
Thanks,
GM
Edited by: user12068331 on Sep 28, 2010 2:17 PM
Edited by: user12068331 on Sep 28, 2010 2:48 PMOk,
Few things to clarify first :
1 - How do you define week number ?
Oracle has 2 different way for week number : normal week number (WW) and isoweek (IW).
is your weeknumber one of those, or is it something else ?
2 - Depending on the country the week doesn't start on the same day : in France (as most of Europe I think) first day is monday, where in the USA (as far as I know) first day is sunday.
the to_char builtin function can display weeknumber :with a as (
--week 0
select 0 as weeknum, to_date('30-MAY-2010','DD-MON-YYYY') as edate, 'JJ' as name from dual union all
select 0 as weeknum, to_date('31-MAY-2010','DD-MON-YYYY') as edate, 'MK' as name from dual union all
select 0 as weeknum, to_date('01-JUN-2010','DD-MON-YYYY') as edate, 'MK' as name from dual union all
select 0 as weeknum, to_date('01-JUN-2010','DD-MON-YYYY') as edate, 'BK' as name from dual union all
select 0 as weeknum, to_date('01-JUN-2010','DD-MON-YYYY') as edate, 'JJ' as name from dual union all
select 0 as weeknum, to_date('04-JUN-2010','DD-MON-YYYY') as edate, 'KK' as name from dual union all
select 0 as weeknum, to_date('04-JUN-2010','DD-MON-YYYY') as edate, 'LA' as name from dual union all
-- week 1
select 1 as weeknum, to_date('06-JUN-2010','DD-MON-YYYY') as edate, 'BK' as name from dual union all
select 1 as weeknum, to_date('06-JUN-2010','DD-MON-YYYY') as edate, 'JJ' as name from dual union all
select 1 as weeknum, to_date('07-JUN-2010','DD-MON-YYYY') as edate, 'KK' as name from dual union all
select 1 as weeknum, to_date('11-JUN-2010','DD-MON-YYYY') as edate, 'LA' as name from dual
select to_char(a.edate,'IW') isoweek, to_char(a.edate,'WW') numweek, a.*
from a;
IS NU WEEKNUM EDATE NA
21 22 0 Sunday 30/05/2010 00:00:00 JJ
22 22 0 Monday 31/05/2010 00:00:00 MK
22 22 0 Tuesday 01/06/2010 00:00:00 MK
22 22 0 Tuesday 01/06/2010 00:00:00 BK
22 22 0 Tuesday 01/06/2010 00:00:00 JJ
22 23 0 Friday 04/06/2010 00:00:00 KK
22 23 0 Friday 04/06/2010 00:00:00 LA
22 23 1 Sunday 06/06/2010 00:00:00 BK
22 23 1 Sunday 06/06/2010 00:00:00 JJ
23 23 1 Monday 07/06/2010 00:00:00 KK
23 24 1 Friday 11/06/2010 00:00:00 LA
11 rows selected. -
How to select records based on Max/Min on different columns and group by
I have a table with 5 columns(a,b,c,d,e), i need to select records based on MAX(c),Max(D) and Min(e) group by a,b. i am trying using : select max(c),max(d),min(e) from table group by a,b. this is not working. its giving me 1 6 1
a b c d e
1 1 1 2 1
1 1 1 6 4
1 1 1 6 3
when i group by a,b i am expecting the record 1 6 3
Please help me with this.. Thanks in advance....Hi,
Welcome to the forum!
962163 wrote:
I have a table with 5 columns(a,b,c,d,e), i need to select records based on MAX(c),Max(D) and Min(e) group by a,b. i am trying using : select max(c),max(d),min(e) from table group by a,b. this is not working. its giving me 1 6 1
a b c d e
1 1 1 2 1
1 1 1 6 4
1 1 1 6 3
when i group by a,b i am expecting the record 1 6 3It looks to me like "1 6 1" is the correct answer. You're asking for the lowest value of e, and 1 is lower than 3.
Maybe you don't want MIN (e). Explain why you want 3 (that is, how you decided that 3 is the correct value for the last column) and someone will help you code it.
Edited by: Frank Kulash on Sep 28, 2012 6:17 PM
Whenever you have a problem, you should psot CREATE TABLE and INSERT statements for your sample data. That way, the people who want to help you can re-create the problem and test their ideas. It often helps to clarify the problem, too. since this is your first message, I'll do it for you:
CREATE TABLE table_x
( a NUMBER
, b NUMBER
, c NUMBER
, d NUMBER
, e NUMBER
INSERT INTO table_x (a, b, c, d, e) VALUES (1, 1, 1, 2, 1);
INSERT INTO table_x (a, b, c, d, e) VALUES (1, 1, 1, 6, 4);
INSERT INTO table_x (a, b, c, d, e) VALUES (1, 1, 1, 6, 3);
COMMIT; -
Info record based on lead time
How to create info record based on Lead time.
If vendor supplies material with in 5 days cost will be 5 dollars each
if he supplied after 5 days cost will be 3 dollars.
how to control this function in info record or in Purchase order or in Conditions.
Thanks
SUNIL KUMARclosed
-
Insert Records Based on User requirement
Hi,
I want to Create a set of records based on the user input defined on run time.
According to my present query i am able to create records which is predefined in 'NoOfRows' variable . Hence when i click on this button, by default 2 rows are inserted in my page.
My requirement is to get the 'NoOfRows' from user, hence i added an input text in my Jsf page which gets the value from user and based on that the rows will be inserted. But i coudn't pass my Rich input text value to this variable. i.e 'NoOfRows'. How is this possible to pass my input text value which is defined in my bean to the java class defined in Application Moldule?
This is my code written in AppModuleImpl.java
public void insertDefaultRows(){
ViewObjectImpl Lines = this.getEmpView1();
Lines.executeEmptyRowSet();
int NoOfRows=2;
oracle.jbo.server.ViewRowImpl emptyRow;
for (int i=0; i < noOfRows;i++){
emptyRow = (oracle.jbo.server.ViewRowImpl)Lines.createRow();
emptyRow.setNewRowState(oracle.jbo.Row.STATUS_INITIALIZED);
Lines.insertRow(emptyRow);
This is my backing bean defined for the input text
public void setIt11(RichInputText it11) {
this.it11 = it11;
public RichInputText getIt11() {
return it11;
Hope I'm clear. Any help?First of all you have to change the signature of the method in the AM to
public void insertDefaultRows(int num){
if (num <= 0)
return;
ViewObjectImpl Lines = this.getEmpView1();
Lines.executeEmptyRowSet();
int NoOfRows=num;
oracle.jbo.server.ViewRowImpl emptyRow;
for (int i=0; i < noOfRows;i++){
emptyRow = (oracle.jbo.server.ViewRowImpl)Lines.createRow();
emptyRow.setNewRowState(oracle.jbo.Row.STATUS_INITIALIZED);
Lines.insertRow(emptyRow);
}then you expose this method to the client interface of the AM. This makes it available in the data control.
Next you should add a variable in the executable section of the bindings of the page.
1) open the bindings of the page
2) right click on the variables in the executables section and choose 'Insert Inside Variables'->'variable'
3) in the dialog set a name e.g. noOfRows with type java.lang.Integer
4) click the green '+' sign in the Bindings section, select AattributeValues, cklick OK
5) select 'variables' as datasource and 'noOfRows' as attribute
This will create a variable of type integer in the bindings of the page. This can be used to store the value of the inputText component. For this select the inputText in your page and in the property inspector add
#{bindings.noOfRows1.inputValue}to the value property. This will transfer the input from the inputText to the variable you created.
Now open the DataControll and drag the method onto the page and drop it as a button. You then get a dialog where you see the 'num' parameter of the method. In the value field you write the binding you used to store the value from the inputText (#{bindings.noOfRows1.inputValue}).
Last thing to do is to set the autoSubmit property of the inputText to true.
This will pass the value from the inputtext to the method.
Timo
Edited by: Timo Hahn on 20.03.2013 13:48
Oh, and you can remove the binding of the inputText to the bean as this is not needed! -
Retrieving field from original records based on current related records transaction date
Post Author: Barbara W
CA Forum: Data Connectivity and SQL
I've been working with Crystal for awhile but am having trouble figuring out how to tell CR what I need to pull from a ledger table I am working with.
I need to identify fees and costs written off. However, once they are written off, the code on the new transaction that identifies fees and costs changes to WOFF. The write off transaction dates I need are in YTD 2007, however, the original transaction in my example is in 2006.
Therefore, I need to pull orginal record of fees, orginal record of costs, then write off record of each for a total of 4 records based on transaction date of the write off records
cust #
invoice #
trans date
credit id
index #
amount
code
1458
1195
7/11/06
458
250
FEES
1458
1195
7/11/06
459
2.52
COST
1458
1195
2/26/07
458
460
250
WOFF
1458
1195
2/26/07
459
461
2.52
WOFF
The credit id matches the index of the original transaction, however, it is on another record. What I am trying to do is pull any record with a credit id, however, I also need to know the original code that goes with that record I.e. FEES/COST.
Any help would be greatly appreciated!!Post Author: SKodidine
CA Forum: Data Connectivity and SQL
Have you tried a subreport? Try creating a subreport and link it with index# to credit id (if you can). This way, for every main record if there is a corresponding subreport record with a credit id, you can retrieve the required information. Otherwise, if you cannot link it as mentioned above, then link it on Cust# but in the main report fetch those with a null credit id and in the subreport fetch those records where credit is not null. You might have to play around with it a bit. Hope it helps! -
Identifying records based on one or more common fields
Hi all
This should be easy - but going round in circles. I want to be able to group together records based on whether at least one field is the same as the corresponding field in a different record.
So:
Account No Tel No PostCode
ABC123 17654231 TS24 4ZX
DEF987 8764573 NE1 1AL
QWE921 17654321 SR9 8BD
ASD579 24697615 SR9 8BD
So in the above example the first, third and fourth record would all form one group because the first links to the third based on Tel No and the third links to the fourth based on PostCode. The second record will be in a group of its own. I want to output the above (into a new table) with an additional field linking relevant records together (a group number).
My first pass was to simply:
select the minimum group number from the output table where either the Tel No or Phone No match the current record. If no match then create a new record for this record with the next incremental group number.
This would give
Account No Tel No PostCode Group
ABC123 17654231 TS24 4ZX 1
DEF987 8764573 NE1 1AL 2
QWE921 17654321 SR9 8BD 1
ASD579 24697615 SR9 8BD 1
On the surface that looks OK. The problem occurs if for instance the PostCode in the second record is 'SR9 8BD'. The output would be identical to the above - but I want them to all share the same group number as now there is some commonality between all four records. I'm sure I need to do something recursively but just can't get my head around it.
Would really appreciate some help.
Thanks
IanHi, Ian,
Welcome to the forum!
Be sure to read the forum FAQ {message:id=9360002} It contains several tips that can help you get good answers quickly
976560 wrote:
Hi all
This should be easy - but going round in circles.Ironically, the solution below involves NOCYCLE.
I want to be able to group together records based on whether at least one field is the same as the corresponding field in a different record.
So:
Account No Tel No PostCode
ABC123 17654231 TS24 4ZX
DEF987 8764573 NE1 1AL
QWE921 17654321 SR9 8BD
ASD579 24697615 SR9 8BDWhenever you have a problem, please post CREATE TABLE and INSERT statments for all tables inolved. Since this is your fist message, I'll do it for you:
DROP TABLE table_x;
CREATE TABLE table_x
( Account_No VARCHAR2 (10) PRIMARY KEY
, Tel_No VARCHAR2 (10)
, Post_Code VARCHAR2 (10)
INSERT INTO table_x (account_no, tel_no, post_code)
VALUES ('ABC123', '17654321', 'TS24 4ZX');
INSERT INTO table_x (account_no, tel_no, post_code)
VALUES ('DEF987', '8764573', 'NE1 1AL');
INSERT INTO table_x (account_no, tel_no, post_code)
VALUES ('QWE921', '17654321', 'SR9 8BD');
INSERT INTO table_x (account_no, tel_no, post_code)
VALUES ('ASD579', '24697615', 'SR9 8BD');
COMMIT;
So in the above example the first, third and fourth record would all form one group because the first links to the third based on Tel No Be careful! It looks like you made a typo there. I changed the number ending in '231' to '321'.
and the third links to the fourth based on PostCode. The second record will be in a group of its own. I want to output the above (into a new table) with an additional field linking relevant records together (a group number).
My first pass was to simply:
select the minimum group number from the output table where either the Tel No or Phone No match the current record. If no match then create a new record for this record with the next incremental group number.
This would give
Account No Tel No PostCode Group
ABC123 17654231 TS24 4ZX 1
DEF987 8764573 NE1 1AL 2
QWE921 17654321 SR9 8BD 1
ASD579 24697615 SR9 8BD 1
On the surface that looks OK. The problem occurs if for instance the PostCode in the second record is 'SR9 8BD'. The output would be identical to the above - but I want them to all share the same group number as now there is some commonality between all four records. I'm sure I need to do something recursively but just can't get my head around it.You said it exactly: you need to do something recursively.
What features of Oracle SQL are recursive? CONNECT BY (as shown below) and, starting in Oracle 11.2, recursive WITH clauses.
Would really appreciate some help.Here's one way to do that:
CREATE TABLE table_y
AS
WITH got_related_account_no AS
SELECT table_x.*
, CONNECT_BY_ROOT account_no AS related_account_no
FROM table_x
CONNECT BY NOCYCLE account_no != PRIOR account_no
AND ( tel_no = PRIOR tel_no
OR post_code = PRIOR post_code
-- OR ... -- other columns as needed
SELECT account_no, tel_no, post_code
, DENSE_RANK () OVER (ORDER BY MIN (related_account_no))
AS grp
FROM got_related_account_no
GROUP BY account_no, tel_no, post_code
;This will work in Oracle 10.1 and up.
At the end of this, table_y contains:
ACCOUNT_NO TEL_NO POST_CODE GRP
ABC123 17654321 TS24 4ZX 1
ASD579 24697615 SR9 8BD 1
DEF987 8764573 NE1 1AL 2
QWE921 17654321 SR9 8BD 1
Maybe you are looking for
-
Missing font in all font menus?
I've only recently updated to OSX and Freehand MX (I've been using Freehand 8 and 9). Everything works okay, but one of my company's key fonts does not appear in the menu. ITC Franklin Gothic Book is simply gone, although it shows up in Photoshop and
-
Excel printing looks out of alignment
All in One C410A. Print works fine in all programs except MS Excel. My printouts look like the printheads are out of alighnment; both vertical and horizontal depending on the file. This did not happen until I moved to the C410. My old C309 the print
-
I accidentally reset my iphone and it the little circle just keeps spinning
its been doing this for 2 hours and i kinda nood to use my phone. it is all backed up, but i would prefer not to lose my in app date.
-
Simple Drawing Application?
I am trying to work out a loading of a ship with all the dimensions I have... Is there a simple drawing app like Visio for windows (which comes with office) for the Mac?? I would like to do it to scale, looked on version tracker/ mac update but canno
-
Webcam instant failure to install
Hi guys, have just bought the webcam instant which comes with game star games, however neither of the 2 disc start up, each one logging a fatal error message, so i cant even install the software. Help please! Paul