Display records from two tables in a Repeat Region
I have 2 tables tblNames and tblResults
tblNames
NamesID PK
FirstName
LastName
Address1
Addrees2
tblResults
ResultsID PK
NamesID FK
ResultsInfo
ResultsDate
Results table has a foreign key NamesID containing primary
key of Names table.
I am trying to show a repeat region of results, with a column
showing LastName of tblNames depending on the ResultsID
I have 2 recordsets, rsNames and rsResults but I'm having
trouble showing relevant LastName.
Create a new recodset or modify one of the old ones with this
sql:
SELECT LastName, ResultsInfo, ResultsDate
FROM tblResults INNER JOIN tblNames USING (NamesID)
ORDER BY LastName
This will produce a list of LastNames and associated info
Dave Buchholz
I-CRE8
www.i-cre8.co.uk
Skype ID: I-CRE8
"Swn-Y-Mor" <[email protected]> wrote in
message
news:f1ndo2$cp9$[email protected]..
>I have 2 tables tblNames and tblResults
>
> tblNames
> --------
> NamesID PK
> FirstName
> LastName
> Address1
> Addrees2
>
> tblResults
> ----------
> ResultsID PK
> NamesID FK
> ResultsInfo
> ResultsDate
>
> Results table has a foreign key NamesID containing
primary key of Names
> table.
>
> I am trying to show a repeat region of results, with a
column showing
> LastName
> of tblNames depending on the ResultsID
> I have 2 recordsets, rsNames and rsResults but I'm
having trouble showing
> relevant LastName.
>
Similar Messages
-
Create a procedure which requires displaying information from two tables
What if we want to create a procedure which requires displaying information from two tables. In this situation,
I need to display all the details of an employee from an 'emp' table based on the deptno. and also their salary information which is
stored in "Salgrade" Table. Is the use of "And" the correct way of using it?
Do I need to declare all the attributes before begin or I can just access them directly? Thanks
Create Procedure findDept
( I_deptno IN number
) As
Begin
Select Ename, Job, MGR, Hiredate, Sal, Comm, Dept_no from emp and exp, grade , location from salgrade where dept_no
= I_Deptno;
Exception
When NO_Data_Found then
DBMS_Output.Put_Line(' Department not found"|| I_deptno);
End findDept;Hi,
Besides Qwerty's remark, you've also got a quoting error:
Change
DBMS_Output.Put_Line(' Department not found"|| I_deptno);
{code}
into
{code}
dbms_output.put_line(' Department not found: '|| i_deptno);
{code}
Which leads to the question:
What do you want to do when a record is found?
Display it? -
Help with listing records from two tables
Hi: I have two tables joined by the first field. The field is primary key in first table. Need help listing records from both tables with each record one line/record.
create table EVENTS (
event_key varchar2(64) primary key,
event_description varchar2(64),
create_time int
create table EVENT_UPDATES (
event_key varchar2(64) NOT NULL ,
update_description varchar2(64),
update_time int
insert into EVENTS values('Event1', 'This is event1', 1);
insert into EVENT_UPDATES values('Event1', 'Ticket created', 3);
insert into EVENT_UPDATES values('Event1', 'Event cleared', 10);
insert into EVENTS values('Event2', 'This is event2', 4);
insert into EVENT_UPDATES values('Event2', 'Ticket created', 6);
insert into EVENT_UPDATES values('Event2', 'Event cleared', 8);I want to print each record in EVENTS table as one line and corresponding records in EVENT_UPDATES as one line/record like this
Event1 1 This is event1
3 Ticket created
10 Event cleared
Event2 4 This is event2
6 Ticket created
8 Event clearedTIA
Raviselect case weight
when 1 then event_key
end key,
time_val,
description
from (
select event_key,
create_time time_val,
event_description description,
1 weight
from events
union all
select event_key,
update_time,
update_description,
2 weight
from event_updates
order by event_key,
weight
KEY TIME_VAL DESCRIPTION
Event1 1 This is event1
3 Ticket created
10 Event cleared
Event2 4 This is event2
6 Ticket created
8 Event cleared
6 rows selected.
SQL> SY. -
Can i select Records from two tables into an itab.
Hi,
Suppose that i have two tables spfli and sflight.
Now i want the records from both the tables into a single internal table.
If so please let me know how this can be done.
itab should consist of all the columns in sflight and spfli.
Regards,
SaiSai,
Yes u can do it using JOINs.
Use this link for ref
http://www.sap-img.com/abap/inner-joins.htm
INNER JOIN results are an intersection of the tables being joined where in only if both the tables havethe data the result is pused onto the result set.
WHERE as in LEFT OUTR JOIN you can push the data of the LEF T table on the resultset even when the join condition is not met.
The use is that you wantto have all the data that is there in left table and also the right table if the join condition is a success then right table fileds will have data else they are initial.
OUTJOIN's are used in MAINTENANNCE VIEWS, HELP VIEWS .
INNER JOINS are used DATABSE VIEWS.
Inner Join:-
SELECT pcarrid pconnid ffldate bbookid
INTO CORRESPONDING FIELDS OF TABLE itab
FROM ( ( spfli AS p
INNER JOIN sflight AS f ON pcarrid = fcarrid AND
pconnid = fconnid )
INNER JOIN sbook AS b ON bcarrid = fcarrid AND
bconnid = fconnid AND
bfldate = ffldate )
WHERE p~cityfrom = 'FRANKFURT' AND
p~cityto = 'NEW YORK' AND
fseatsmax > fseatsocc.
Left Outer Join
SELECT scarrid scarrname p~connid
INTO CORRESPONDING FIELDS OF TABLE itab
FROM scarr AS s
LEFT OUTER JOIN spfli AS p ON scarrid = pcarrid AND
p~cityfrom = 'FRANKFURT'.
Reward if helpful,
Karthik -
Records from two tables in different DB's
I have two tables (in different DB's) that I need to build
results from. I want to return results from all records in table A
and when a matching record in table B is found, retrieve the value
of a sqlbit field. The catch is that there may or may not be any
records in Table B that match Table A, and there may be more than
one record in Table B, but always only one record for Table A.
Table A is [Order] (yes I know, a reserved word - not my
design) and Table B is tblOrderFollowup - here is my current SQL
statement:
****************BEGIN SQL*************************
SELECT o.StoreID AS xStore
, o.Time AS dCreated
, o.ID AS xPurchase
, c.FirstName AS sFirstName
, c.LastName AS sLastName
, c.Company AS sCompany
, c.ID AS xCustomer
, o.Type AS xType
, o.Closed AS bClosed
, o.Tax AS nTax
, fu.OrderID AS xFUOrder
, fu.bComplete AS xFUComplete
FROM [Order] o
INNER JOIN Customer c
ON o.CustomerID = c.ID
AND o.StoreID = c.StoreID
LEFT OUTER JOIN db2.dbo.tblOrderFollowup fu
ON o.ID = fu.OrderID
AND o.StoreID = fu.StoreID
WHERE o.StoreID IN ( #allowableStoreIDs# )
AND o.StoreID = <cfqueryparam cfsqltype="cf_sql_integer"
value="#FORM.StoreID#" />
AND o.Time >= <cfqueryparam
cfsqltype="cf_sql_timestamp"
value="#CreateODBCDateTime(StartOfDay(FORM.dFrom))#" />
AND o.Time <= <cfqueryparam
cfsqltype="cf_sql_timestamp"
value="#CreateODBCDateTime(EndOfDay(FORM.dTo))#" />
AND o.Closed = <cfqueryparam cfsqltype="cf_sql_bit"
value="1" />
ORDER BY o.Time DESC
***********END SQL**********************
The problem here is that when I have more than 1 record per
OrderID/StoreID pair in Table B, I get more than one result - I
only want one. I am guessing I need a sub query, but don't know how
to go about doing that at all ...You say you want only one result. Do you know which one you
want?
By the way, your query is probably not giving you the right
answer. My experience is that if you do this:
select stuff
from table1 left join table2 on something
where table2.somefield = somevalue
you get the wrong answer. What I do instead is,
select stuff
from table1 left join
(select stuff from table2
where whatever) need_an_alias on somthing -
How do I extract matching records from two tables?
I'm trying to extract client records from our client database to put together a very targeted email campaign. As an example, the result I want is a list of names and email addresses of those clients who have a record in our system, have not had a visit in our clinic in the last year, and live within 200 miles of our clinic. I can capture the first two criteria in one extract, and the second in another. I can then import those as tab delimited data into Numbers. What I then need to do is create a third table that represents ONLY those records that exist in both tables.
Can someone tell me if this is possible and if so, how to do it?
I'd be very appreciative of any help, thank you.conejo61 wrote:
I can then import those as tab delimited data into Numbers. What I then need to do is create a third table that represents ONLY those records that exist in both tables.
You can create a column that generates a serial marker on the table from which you want to transfer the data, making all the names that also appear on the other table. Not that the formula will mark only exact matches.
Here's a short example:
Table 1 on the left, is one of the two tables imported from the tab delimited data files. It has other data, but only the names in column A are used to identify records appearing on both tables.
Table 2 on the right, contains the names and other data (represented by the email addresses in column B), to be transferred to the third table.
Column C of this table contains the formula that counts off the rows containing names appearing on both tables. The version below is in C2, and is filled down to the end of the column.
=IF(COUNTIF(Table 1 :: $B,A2)>0,MAX($C$1:C1)+1,"")
Note that jane Doe is not counted (or transferred) as her name is recorded differently on the two tables.
Table 3 is the results table. It contains one formula for each column to be transferred from Table 2 to Table 3.
A2: =IF((ROW()-1>MAX(Table 2 :: $C)),"",LOOKUP(ROW()-1,Table 2 :: $C,Table 2 :: $A))
B2: =IF((ROW()-1>MAX(Table 2 :: $C)),"",LOOKUP(ROW()-1,Table 2 :: $C,Table 2 :: $B))
Regards,
Barry
EDIT: I was working in Numbers '09 when developing this, and got the following warning when I saved a copy as an iWork '08 document:
Referencing row or column ranges that include header or footer cells isn't supported. The formula references were updated to exclude header and footer cells.
The formulas in Table 2::C2 references C1. You may have to ensure that Table 2 does not include a header row.
B.
EDIT2: A check on the file in Numbers '08 showed no apparent change to the formula, and editing Jane Doe's name on table 1 resulted in her name being added to Table 3.
Message was edited by: Barry -
Delete records from two tables
Hi All,
I have two tables (tableA and tableB) and i have four combination primary key.
How can I delete the records from tableA that are not in tableB?
In my sample below I need to delete the records from year 2013.
I have a loop to insert the new ones.
Thanks
Johnny
create table tableA(
keyA_id number,
keyB_id number,
keyC_id number,
keyD_id number,
amount number,
CONSTRAINT "PK_TABLEA" PRIMARY KEY (keyA_id, keyB_id, keyC_id, keyD_id)
insert into tableA(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,1,2011,10);
insert into tableA(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,1,2012,40);
insert into tableA(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,1,2013,20);
insert into tableA(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,2,2011,10);
insert into tableA(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,2,2012,30);
insert into tableA(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,2,2013,20);
create table tableB(
keyA_id number,
keyB_id number,
keyC_id number,
keyD_id number,
amount number,
CONSTRAINT "PK_TABLEB" PRIMARY KEY (keyA_id, keyB_id, keyC_id, keyD_id)
insert into tableB(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,1,2011,10);
insert into tableB(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,1,2012,40);
insert into tableB(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,1,2014,40);
insert into tableB(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,2,2011,10);
insert into tableB(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,2,2012,30);
insert into tableB(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,2,2014,30);r you trying to do something like below ?
Delete from TableA A
where not exists (select 1 from TableB B where
A.keyA_id=B.keyA_id and
A.keyB_id=B.keyB_id and
A.keyC_id=B.keyC_id and
A.keyD_id=B.keyD_id) -
Hi all,
I have two tables:
CRETE TABLE T1 (T1_COL1 NUMBER, T1_COL2 NUMBER)
CRETE TABLE T2 (T2_COL1 NUMBER, T2_COL2 NUMBER)
T1 may or may not have records. T2 always has records. There are two scenarios.
Scenario 1:
=======
SELECT * FROM T1 returns five rows, and SELECT * FROM T2 returns 10 rows.
Now I need the five rows from T1.
Scenario 2:
=======
SELECT * FROM T1 returns zero rows, and SELECT * FROM T2 returns 10 rows.
Now I need the 10 rows from T2.
In other words, if records present in T1, I need them all. If not, I need records from T2.
There are no common columns (for joins).
Now need a single query to achive this. I tried set operators, CASE and DECODE. But I'm unable to solve it.
Please help. Thanks in advance.Iniyavan wrote:
Yes, Justin. I'm sure that this is the way it's modelled. I also find it's tough and odd.Are you sure it's the right way for that data to be modeled? I understand that's the way it is being modeled, but a data model change may be the best option.
Is there any other way, which is simpler, without using RANK?That's the simplest option I can think of. You could also do something like
SELECT t1_col1, t1_col2
FROM (
SELECT t1_col1, t1_col2, rownum rn
FROM (
SELECT t1_col1, t1_col2
FROM (
SELECT t1_col1, t1_col2, 1 tbl
FROM t1
UNION ALL
SELECT t2_col2, t2_col2, 2 tbl
FROM t2
ORDER BY tbl
WHERE rn = 1I'm not sure that's any simpler...
Justin -
Display columns from two tables without making join
Hi,
I need to perform currency conversion in the report.
For eg:) Whatever the currency in ar_payment_schedules i want to
convert it to INR equivalent.
Following is the query to do this.
select ps.invoice_currency_code Currency_B,
decode(ps.invoice_currency_code, 'INR',ps.amount_due_original,
round(ps.amount_due_original*
ps.exchange_rate,
curr.precision)
from
ar_payment_schedules ps,
fnd_currencies curr
where ps.customer_id = '111'
and curr.currency_code = 'INR'
When i do this in the Administration tool, the answers modules erroring out saying
that no joins between ar_payment_schedules and fnd_currencies. But here join is
not needed becuase fnd_currencies is filtered with INR and will return only
one row. Without joining two tables how can i get the same results in Answers.
thanks,
PrasannaIf it would return only one row then what is the need for the join (is it just for returning the precision?). Cant you just hard code the precision value instead of getting it from the table? Also you are doing a cartesian join, though the filters would take care of the final output this would result in a bad performance as your data starts scaling out. You need to find a key to join these 2 tables. If you do not have one, then just create a view with the cartesian join alone and then use that in your report.
Thanks,
Venkat
http://oraclebizint.wordpress.com -
I have two tables - table1 and table2 - that have the exact same schema. There are three fields that can be used to compare the data of the two tables, field1, field2, and field3. When there are matching rows in the two tables (table1.field1/2/3 = table2.field1/2/3)
I want to replace table1.field4 with table2.field4 and replace table1.field5 with table2.field5.
I have worked with the query but have come up with goobly goop. I would appreciate any help. Thanks.If your field1, field2, and field3 combinations in these tables are unique, you
can do a join on them.
Select t1.field4, t2.field4 , t1.field5, t2.field5
from table1 t1 inner join table2 t2 on t1.field1 =t2.field1 and t1.field2=t2.field2 AND t1.field3=t2.field3
--You can update your table1 with following code:
Merge table1 t1
using table2 t2 on
on t1.field1 =t2.field1 and t1.field2=t2.field2 AND t3.field3=t2.field3
When matched then
Update Set
t1.field4= t2.field4
,t1.field5 = t2.field5 ; -
How to access records from two tables which have no relation
Hi,
I trying to generate a report where i need to print the company details at the top of the page and invoice details of that down the page.There is no relation between these two tables.I am not able to write two queries for one report.Pls some one assist me in getting this thing done.
Regards,
Tulacenath.Hi Tulacenath
So your invoice table does not have a reference to the customers (companys) that the invoices belong to?
Tim -
How to display records from base table as well as some other table?
Hello expert,
I have a requirement to develope a form described below:
One control block and database block.
DB block is based on table T1 (USER, Table_name, Column_name, ACCESS);
In control block, there are three fields,
User, Table user will enter , and DB block will query based on control block fields(user, table_name).
In table it is not necessary that all the columns of any table will be given.
suppose there is a Table X consist of 10 column.
Initially user give access for all the 10 columns through this form.
if we query for user , table, all the record will come from table T1.
now consider the case, when access given to table X number of columns were 10. after that 2 new columns added later.
now there is no info of added column in table T1. i want if user query DB block, these newly added column must display in DB Block.
Please help me out.
Thanks
Dhirender>i want if user query DB block, these newly added column must display in DB Block.
You need to modify your form and add the two columns as base table items. Forms does not add two base table items by itself. -
Displaying record from custom table
I have a custom table ztable (kunnr, vbeln, erdat, erzet, flag). Using these values I would like to display the following
Client Number (4) = '1234'
Filler (6) = space.
Record Type (1) = 'A'
Client Number (15) = vrkpa-kunnr
Customer Name (30) = adrc-name1
This information should be displayed in the following way:
1234 A0012345 Walmart
Can someone help me with this code.
Thank you!Okay, I see. Is your client number always going to be '1234'? If not, then do not assign a value to it. Otherwise, you'll want to assign the value during your selection statement because the field will be emptied each time you clear the itab line.The same thing goes for your record type 'A'. You need an address number, a date, and a nation as the key for table ADRC (so you need to put the necessary values into w_nation and w_begda). I'm not sure if your customer number corresponds to the address number. Try this:
DATA wa_ztable TYPE ztable.
DATA wa_adrc TYPE adrc.
DATA w_nation type adrc-nation.
DATA w_begda type sy-datum.
DATA: begin of itab occurs 0,
clientnumber(4) type c,
filler(2) type c,
recordtype(1) type c,
customernumber(15) type c,
customername(30) type c,
customeraddress1(30) type c,
customeraddress2(30) type c,
customercity(17) type c,
customerstate(2) type c,
customerzip(9) type c,
customercountry(17) type c,
customercountrycode(3) type c,
customerphnum(10) type c,
end of itab.
w_begda = (put your date here).
w_nation = (put your nation code here).
SELECT * FROM ztable INTO wa_ztable WHERE flag = space.
itab-clientnumber = '1234'.
itab-filler = space.
itab-rectype = 'A'.
itab-customernumber+0(10) = wa_ztable-kunnr.
itab-customernumber+10(5) = space.
SELECT SINGLE * FROM TABLE adrc INTO wa_adrc WHERE
ADDRNUMBER = wa_ztable-kunnr AND NATION = w_nation AND DATE_FROM = w_begda.
itab-customername = wa_adrc-name1.
itab-customeraddress1 = wa_adrc-
itab-customeraddress2 = wa_adrc-
itab-customercity = wa_adrc-city1.
itab-customerstate = wa_adrc-regiogroup.
itab-customerzip = wa_adrc-post_code1.
itab-customercountry = wa_adrc-
itab-customercountrycode = wa_adrc-country.
itab-customerphnum = wa_adrc-tel_number.
append itab.
clear itab.
ENDSELECT.
LOOP AT itab.
*Insert your code to display line here (can just list each itab field, or use column numbers if you want to create spaces between the fields)
ENDLOOP.
Note on the * lines: I don't see a field for the country text. For the address lines, you will probably have to concatenate values from ADRC-HOUSE_NUM1 and ADRC-STREET, and possibly also use ADRC-PO_BOX as well.
- April
Message was edited by:
April King -
Display records from database table
My database table has 495K records i want to display them all in se11 tcode and than download into excel ...but because of huge records it timeout.
Do I need to write a program for this?
Or is there any other smarter way.
Regards,
DNPHi,
Please follow the steps below:
1. Go to the selection screen of SE11 and provide your selection criteria (if required).
2. Click on Settings menu->User parameters->ALV Grid display.
3. Now click on Program menu->Execute in background->Provide output device name as LP01 or LOCAL or any valid printer parameters->Click continue->Click Immediate button->Click Save.
4. You can see the background job for this in SM37.
5. Once the background job is completed, it will appear in gleen color.
6. Click on the completed job and then click on Spool button.
7. Once the output is displayed in spool you can now easily download it to excel by clicking on System menu->List->Save->Local File.
Hope this will help you.
Regards,
Venkat -
Matching records from two tables even when the ID of a person is null.
I have a MySQL named Natural Systems which is a magazine account that it member's will both sell handmade items wherein the proceeds will go into the Natural Systems account and each member also give a weekly donation. All of the proceeds will help toward the printing of the subsequent volumes. both of the selling of handmade items and the weekly dues happens during the same week or the same magazine volume number. I am trying to write a query that will pull both of the sales as well as the weekly dues payments weather they have paid or not.
SELECT foiid, trim(concat(name.fname,' ',name.lname)) AS no_ns, nspayamt, DATE_FORMAT(nspaydate, '%m/%d/%Y') FROM name LEFT JOIN nspay ON nspayfoiid = foiid and volume = '27' WHERE nspayfoiid is null AND type = 'Registered' AND city = 'richmond' AND status = 'a' group by foiid ORDER BY no_ns
This code will bring up the following names of those who did not pay weekly dues during volume 2:
Christopher Gabb
Michael banks
Timothy Hardin
However there is another table I wish to call the same Individuals who sold magazine during the same week of volume 27
SELECT trim(CONCAT(name.fname,' ',name.lname))AS Sold,
round(sum(fcnsales.salesamt)) as TOTAL_Mags_SOLD FROM name, fcnsales WHERE fcnsales.salesfoiid = name.foiid
AND fcnsales.salesvolume '27' GROUP BY name.foiid ORDER BY TOTAL_mags_SOLD desc;
This above code produces the following results:
Sold TOTAL_Mags_SOLD
Christopher Gabb 50
Michael banks 36
Timothy Hardin 12
I would like to combine the two queries to produce the following
Sold TOTAL_Mags_SOLD nspayamt
Christopher Gabb 50 none
Michael banks 36 none
Timothy Hardin 12 none
can anyone give me a direction to go to?If your field1, field2, and field3 combinations in these tables are unique, you
can do a join on them.
Select t1.field4, t2.field4 , t1.field5, t2.field5
from table1 t1 inner join table2 t2 on t1.field1 =t2.field1 and t1.field2=t2.field2 AND t1.field3=t2.field3
--You can update your table1 with following code:
Merge table1 t1
using table2 t2 on
on t1.field1 =t2.field1 and t1.field2=t2.field2 AND t3.field3=t2.field3
When matched then
Update Set
t1.field4= t2.field4
,t1.field5 = t2.field5 ;
Maybe you are looking for
-
The title pretty much says it all. Had restored my iTunes music files to a new computer along with all the music and any digital PDF booklets that I had. Trust me the PDF booklets are successfully imported on my new pc but for some reason I am having
-
Add swatch throwing error 1200
I have a simple script which is attempting to add a swatch. However, it is throwing "Error 1200: an Illustrator error occurred: 1312914990 ('NA~.') Line: 18 -> newSpot.colorType = ColorModel.SPOT;" This is an example taken straight from the docs, the
-
Hi, I am working on a web application using struts framework. I know Struts provides internationalization of messages and labels using MessageResources. I have a requirement that all the error messages (not the fields labels on the form) should come
-
"what you hear" playing all the t
I have a onboard soundblaster 24-bit li've. I am not sure exactly what the problem is, but whenever I use a mic I can always hear the background system sounds of my computer on top of my voice (ex. system ding, and music I am playing). I found it har
-
I just updrade MAC 0S X 10.9 can not open Iphoto ( 9.2.3)
I just upgrade my Mac to latest version IOS 10.9 today, after i install this , Iphoto is not woking and my Iphoto is 9.2.3 please let me know what i have to do Thank you, Chris