Joining the data from two Tables
I create a table with six months date from Jan to Jun. Another table with July trough Sept.
Now I want one table in which I am going to at the end of the year have all 2007 fiscal data.
I do not want to restore them ever back to the components. How do I do this?
If I understand you correctly, I think you merely want to enlarge the first table enough to accommodate the data from the second table. Then select the cells in the second table and copy and paste them into the newly created space in the first table. Ask if you need more detail instructions on how to do this.
Similar Messages
-
To Select the data from two table one is transp table and onther is cluster
Hi All,
I want to select the data from two tables
Here i am giving with an example.
Fileds: kunnr belnr from bseg. table bseg
fields: adrnr from kna1 table: kna1.
Know i want to put these into one internal table based on kunnr and belnr.
Thanks in advance.
RameshHi,
U cant use joins on cluster table and BSEG is a cluster table so use FOR ALL ENTRIES for taht
refer this code
*& Form sub_read_bsak
text
--> p1 text
<-- p2 text
FORM sub_read_bsak.
*--Select data from BSAK Table
SELECT lifnr
augdt
augbl
gjahr
belnr
xblnr
blart
dmbtr
mwskz
mwsts
sgtxt
FROM bsak
INTO CORRESPONDING FIELDS OF TABLE it_bsak
WHERE belnr IN s_belnr
AND augdt IN s_augdt.
IF sy-subrc EQ 0.
*--Sort table by accounting document and vendor number
SORT it_bsak BY belnr lifnr.
ENDIF.
ENDFORM. " sub_read_bsak
*& Form sub_read_bseg
text
--> p1 text
<-- p2 text
FORM sub_read_bseg.
IF NOT it_bsak[] IS INITIAL.
*--Select data from BSEG table
SELECT belnr
gjahr
shkzg
kostl
hkont
ebeln
ebelp
FROM bseg
INTO CORRESPONDING FIELDS OF TABLE it_bseg
FOR ALL ENTRIES IN it_bsak
WHERE belnr EQ it_bsak-belnr
AND gjahr EQ it_bsak-gjahr
AND shkzg EQ 'S'.
IF sy-subrc EQ 0.
*--Sort table by accounting document
SORT it_bseg BY belnr.
ENDIF.
ENDIF.
ENDFORM. " sub_read_bseg -
Fetch the data from two tables
hell all
i want to fetch the data from two tables, one is from internal table and another one is data base table. what syntax i have to use either FOR ALL ENTRIES or INNER JOIN?hi
Use FOR ALL ENTRIES.
see the sample code
select * into table tvbrk from vbrk
where fkart in ('F2', 'F3', 'RE',
'ZVEC' , 'ZVEM' , 'ZVED',
'S1')
and erdat in so_erdat
and kunag in s_kunag.
erdat in so_erdat
and fkart in ('F2', 'F3', 'RE',
'ZVEC' , 'ZVEM').
if not tvbrk is initial.
select * into table t_zregion from zregion
for all entries in tvbrk
where country = tvbrk-land1
and region = s_regio.
endif.
thanks
sitaram -
Data from two tables in the same row in XML transformation
Hi,
I am using XML transformation for generating excel file which is to besent as email attachment.
Here I want to display the data from two internal tables in the same row in the excel. .I am using <tt:loop ref=".<table name>"> ... </tt:loop> for looping through the table. Can I loop two table simultaneously ? In that case how will I specify the fields in each table . Some of the fields in two tables are of same name and type.
Please help...
Thanks,
JissaHello Brian,
Thank you for your answer. It is approach I will use, I think. However let me ask: Would it be possible to have a Version in this layout, too? I mean to see, which value comes from Version A and which comes from Version B? Something like this:
Calendar Month Version Sales Amount
2011.01 B 200
2011.02 B 300
2011.03 A 260
2011.04 A 230
2011.05 A 200
A -
Select data from two tables...!
HI Experts...!
i m a beginner user and i want to select data from two tables proj and prps.....using joins.....and internal tables i have written a code...
SELECT prps~pspnr
prps~objnr
prps~psphi
proj~ernam
proj~erdat
proj~pspnr
INTO table itab -
itab is internal table
FROM prps inner join proj
WHERE pspnr in p_no and prpspsphi = projpspnr.
but there is error in from clause ..please help me....
Advance thanx....Hi,
check the sample code bellow above two reply will solve out your problem but one more extra line in your code pointed out bellow.
TABLES: prps, proj.
TYPES: BEGIN OF ty_test,
pspnr LIKE prps-pspnr,
objnr LIKE prps-objnr,
psphi LIKE prps-psphi,
ernam LIKE proj-ernam,
erdat LIKE proj-erdat,
END OF ty_test.
DATA: itab TYPE STANDARD TABLE OF ty_test WITH HEADER LINE.
SELECT-OPTIONS: p_no FOR prps-pspnr.
SELECT prps~pspnr
prps~objnr
prps~psphi
proj~ernam
proj~erdat
* proj~pspnr " No need for this you have selected this in
* the first line because it is commone so you only need to select from any one
INTO TABLE itab
FROM prps INNER JOIN proj ON ( prps~pspnr = proj~pspnr )
WHERE prps~pspnr IN p_no.
Best Regards,
Faisal
Edited by: Rob Burbank on Dec 24, 2009 12:24 PM -
Retrive data from two tables into one internal table.
Hi SDN,
I am downloading the Assets data from two tables ANLA,ANLZ.
there is a common field ANL1in both tables and i have to retrive the data by using anl1 into the internal table.
can you please send me the SELECT Syntax for this probl.....
Thank you & Regards,
ManojHi manoj,
Please see the following sample code. But kindly don't use join as it may hamper ur performance. No trouble in using two select query.
data: begin of itab occurs 0,
BUKRS like anla-BUKRS,
ANLN1 like anla-ANLN1,
BDATU like anlz-BDATU,
end of itab.
select anlabukrs anlaANLN1 anlzBDATU into corresponding fields of table itab from anla inner join anlz on anlaanl1 eq anlz~anl1 where (logexp).
Please come back for any clarification.
Thanks and Regards,
saurabh -
ALV OOps report- getting data from two tables and adding issue
Hi,
This is sales employee performance report.
I need to select all the fields from two tables based on user input ie VKorg, sales employee .
There is one field callled " Net sales"in both the tables.
Based on sales employee number, i need to add that net sales which i get from two tables.
I need to generate single report.
Can you give some inputs reg. the select query.
My idea is select all the data from both tables using join statement.
ThanksHi,
I have written like this:
select * from S002 as a join S006 as b
into table ME->SS002_RAW[]
where vkorg in me->select_parameters->SO_VKORG[] = vkorg in me->select_parameters->SO_VKORG[]
and ZZSLSEMP01 in me->select_parameters->SO_so_empl[] = ZZSLSEMP02 in me->select_parameters->SO_so_empl[].
when i do like that,
I am getting error
Incorrect structure of FROM clause . . . .
If you give some idea on this
Edited by: Raja on Apr 22, 2009 11:19 AM -
Query the data between two tables
Need help for query the data between two tables
Table 1: Time sheet
P.ID P.Name EmpID HoursSpend DateTime
c12234 Test 25 4 06/12/2013
c12234 Test 25 7 06/13/2013
c12234 Test 25 8 06/15/2013
c12234 Test 5 3 06/21/2013
c12234 Test 2 5 07/15/2013
c12234 Test 25 4 07/21/2013
Table 2: cost table
EmpID FromDate ToDate Rate
25 05/01/2013 06/30/2013 250
2 04/01/2013 05/31/2013 150
25 07/01/2013 09/30/2013 300
Output
P.ID P.Name EmpID HoursSpend DateTime Rate Total (HoursSond x Rate)
c12234 Test 25 4 06/12/2013 250 1000 (4*250)
c12234 Test 25 7 06/13/2013 250 1750
c12234 Test 25 8 06/15/2013 250
2000
c12234 Test 25 4 07/21/2013 300
1200
c12234 Test 2 5 07/15/2013 150
750
===========================================
Total 28
6700
============================================
Here EmpID =2 don't have rate in the cost table on july month should be pick from last entry from cost table.Hi Gopal,
According to your description, it seems that the output needn’t include the row when EmpID=2. Because the DateTime for it in Table1 doesn’t included between FromDate column and ToDate column. After testing the issue in my environment, we can refer to the
query like below to achieve your requirement:
SELECT time.*,cost.EmpID,cost.Rate,(time.HoursSpend * cost.Rate)as [Total (HoursSond x Rate)]
FROM [Time sheet] as time
INNER JOIN
[cost table]as cost
ON time.EmpID = cost.EmpID
AND time.DateTime BETWEEN cost.FromDate AND cost.ToDate
If there are any other questions, please feel free to ask.
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
Question about retrieving data from two tables
Hi everyone.
I've been working on this and was wondering what the correct way of handling this would be.
I have two tables, a Billing Table that contains invoices and related information, and a Payments Table that contains payments and related information to that.
Both tables contain a Date Column for the date that the Invoice was generated or the Payment was made.
I want to get a list of all Invoices and the respective payments if the invoice was generated between two dates OR the payment was made between these two dates.
I can get a list of the invoices and their payments if the invoice was generated between those dates. I can get a list of the payments if they were made between those dates. But I can't seem to figure out how to do both.
How do I Join two tables and have it return the data from both tables if either meets the required Date Period?
Here is the SQL that I have so far. This SQL returns all of the Invoices and Payments IF the Invoice was generated between these two dates (Or updated).
SELECT Billing.ID AS [BID], Billing.AttachmentName, Billing.BillingType, Billing.Invoice, Billing.Description, Billing.Amount, Billing.DateCreated AS [BillingDate],
Payments.ID AS [PID], Payments.Type AS PaymentType, Payments.Payment, Payments.PaymentNote, Payments.Reason AS [BillReason], Payments.DateCreated AS [PaymentDate],
Customers.ID AS [CID], COALESCE(NULLIF(Customers.Company,'') + ' - ','') + Customers.LName + ', ' + Customers.FName AS [Name],
Jobs.ID AS [JID], Jobs.JobType, Jobs.JobStatus, Jobs.JobStatusDate
FROM Billing LEFT OUTER JOIN Payments ON Payments.BillingID = Billing.ID
RIGHT OUTER JOIN Customers ON Customers.ID = Billing.CustomerID
RIGHT OUTER JOIN Jobs ON Jobs.ID = Billing.JobID
WHERE
Billing.BillingType = 'Invoice' AND Billing.PaidInFull = 'No' AND Billing.Collections = 'No' AND Billing.ChargeOff = 'No' AND Billing.Lien = 'No' AND Billing.InvoiceCanceled = 'No'
AND (Billing.DateCreated >= '1/1/2014' AND Billing.DateCreated <= '8/13/14') OR (Billing.DateUpdated >= '1/1/14' AND Billing.DateUpdated <= '8/13/14')
ORDER BY Name Asc, Billing.Invoice, PID
Thanks for your help, I really appreciate it.
-Matt-I don't quite follow your query, but your description leads me to think that you need the set of Billing IDs for bills that were created as defined or that have payments that were created as defined. From that set of IDs you then simply want all Bills
and their associated payments. So how do you get that set of IDS? One way is the union operator:
with allbill (billID) as (
select ID from dbo.Billings where DateCreated between ...
union
select BillingID from dbo.Payments where DateCreated between ... )
select ...
from allbill inner join dbo.Billings as bill on allbill.billID = bill.ID inner join dbo.Payments as pay
on bill.ID = pay.BillingID
order by ... ;
Your description leads me to believe that you query is much more complicated, but the basic idea is the union in the CTE - generate one combined set of bill IDs that identify all your bills of interest. Note that I assumed that a payment cannot exist
with an associated billing. -
Insert the data into two tables at a time.
Hi ,
i have these two tables
create table [dbo].[test1](
[test1_id] [int] identity(1,1) primary key,
[test2_id] [int] not null
create table [dbo].[test2](
[test2_id] [int] identity(1,1) primary key,
[test1_id] [int] not null
alter table [dbo].[test1]
add constraint [fk_test1_test2_id] foreign key([test2_id])
references [dbo].[test2] ([test2_id])
alter table [dbo].[test2] add constraint [fk_test2_test2_id] foreign key([test1_id])
references [dbo].[test1] ([test1_id])
I want to insert the data into two tables in one insert statement. How can i do this using T-SQL ?
Thanks in advance.You can INSERT into both tables within one Transaction but not in one statement. By the way, you would need to alter your dbo.Test1 table to allow null for first INSERT test2_id column
See sample code below:
CREATE TABLE #test1(test1_ID INT IDENTITY(1,1),test2_id INT NULL)
CREATE TABLE #test2(test2_ID INT IDENTITY(1,1),test1_ID INT)
DECLARE @Test1dentity INT
DECLARE @Test2dentity INT
BEGIN TRAN
-- Insert NULL as test2_ID value is unknown
INSERT INTO #test1(test2_ID)
SELECT NULL;
-- get inserted identity value
SET @Test1dentity = SCOPE_IDENTITY();
INSERT INTO #test2(test1_ID)
SELECT @Test1dentity;
-- get inserted identity value
SET @Test2dentity = SCOPE_IDENTITY();
-- Update test1 table
UPDATE #test1
SET test2_ID = @Test2dentity
WHERE test1_ID = @Test1dentity;
COMMIT
SELECT * FROM #test1;
SELECT * FROM #test2;
-- Drop temp tables
IF OBJECT_ID('tempdb..#test1') IS NOT NULL
BEGIN
DROP TABLE #test1
END
IF OBJECT_ID('tempdb..#test2') IS NOT NULL
BEGIN
DROP TABLE #test2
END
web: www.ronnierahman.com -
How to upload the data from two sheets in one excel into SAP
Hi experts,
My requirement is to upload the data from two sheets in an excel into an internal table.How can this be achieved.Is some OLE application has to be used?
Thanks
AbhishekHi
see this program will upload excel file to application.
*& Report ZSD_EXCEL2
REPORT ZSD_EXCEL2.
types: begin of ttab ,
fld1(30) type c,
fld2(30) type c,
fld3(30) type c,
fld4(30) type c,
fld5(30) type c,
end of ttab.
data: itab type table of ttab with header line.
selection-screen skip 1.
parameters: p_file type localfile default
'C:\test.xls'.
selection-screen skip 1.
at selection-screen on value-request for p_file.
call function 'KD_GET_FILENAME_ON_F4'
exporting
static = 'X'
changing
file_name = p_file.
start-of-selection.
clear itab. refresh itab.
perform upload_data.
loop at itab.
write:/ itab-fld1, itab-fld2, itab-fld3, itab-fld4, itab-fld5.
endloop.
* Upload_Data
form upload_data.
data: file type rlgrap-filename.
data: xcel type table of alsmex_tabline with header line.
file = p_file.
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = file
i_begin_col = '1'
i_begin_row = '1'
i_end_col = '200'
i_end_row = '5000'
tables
intern = xcel
exceptions
inconsistent_parameters = 1
upload_ole = 2
others = 3.
loop at xcel.
case xcel-col.
when '0001'.
itab-fld1 = xcel-value.
when '0002'.
itab-fld2 = xcel-value.
when '0003'.
itab-fld3 = xcel-value.
when '0004'.
itab-fld4 = xcel-value.
when '0005'.
itab-fld5 = xcel-value.
endcase.
at end of row.
append itab.
clear itab.
endat.
endloop.
endform. -
No data Exists error while retrieving the data from a table
Hi Everyone!
I am getting "No Data Exists" error while retrieving the data from a table....where i need to check...if possible please give me example link.....please help me regarding thisHi !
thanks for ur response...
I have written vo.executeQuery for the table...My page is running but i m not getting the data....I have to select two LOV's and when I click on Go button the data has to display in the table...After the selection of LOV's when I click on Go in the table "No data exists" message is appearing...the table has the data and the query is also executing...please give info where i did the mistake.... -
Cartesian of data from two tables with no matching columns
Hello,
I was wondering – what’s the best way to create a Cartesian of data from two tables with no matching columns in such a way, so that there will be only a single SQL query generated?
I am thinking about something like:
for $COUNTRY in ns0: COUNTRY ()
for $PROD in ns1:PROD()
return <Results>
<COUNTRY> {fn:data($COUNTRY/COUNTRY_NAME)} </COUNTRY>
<PROD> {fn:data($PROD/PROD_NAME)} </PROD>
</Results>
And the expected result is combination of all COUNTRY_NAMEs with all PROD_NAMEs.
What I’ve noticed when checking query plan is that DSP will execute two queries to have the results – one for COUNTRY_NAME and another one for PROD_NAME. Which in general results in not the best performance ;-)
What I’ve noticed also is that when I add something like:
where COUNTRY_NAME != PROD_NAME
everything is ok and there is only one query created (it's red in the Query plan, but still it's ok from my pov). Still it looks to me more like a workaround, not a real best approach. I may be wrong though...
So the question is – what’s the suggested approach for such queries?
Thanks,
Leszek
Edited by xnts at 11/19/2007 10:54 AMWhich in general results in not the best performanceI disagree. Only for two tables with very few rows, would a single sql statement give better performance.
Suppose there are 10,000 rows in each table - the cross-product will result in 100 million rows. Sounds like a bad idea. For this reason, DSP will not push a cross-product to a database. It will get the rows from each table in separate sql statements (retrieving only 20,000 rows) and then produce the cross-product itself.
If you want to execute sql with cross-products, you can create a sql-statement based dataservice. I recommend against doing so. -
Hi
how to create a external content type for Read and Update data from two tables in sqlserver using sharepoint designer 2010
i created a bcs service using centraladministration site
i have two tables in sqlserver
1)Employee
-empno
-firstname
-lastname
2)EmpDepartment
-empno
-deptno
-location
i want to just create a list to display employee details from two tables
empid firstname deptno location
and same time update in two tables
adilWhen I try to create an external content type based on a view (AdventureWorks2012.vSalesPerson) - I can display the data in an external list. When I attempt to edit it, I get an error:
External List fails when attached to a SQL view
Sorry, something went wrong
Failed to update a list item for this external list based on the Entity (External Content Type) 'SalesForce' in EntityNamespace 'http://xxxxxxxx'. Details: The query against the database caused an error.
I can edit the view in SQL Manager, so it seems strange that it fails.
Any advice would be greatly GREATLY appreciated.
Thanks,
Randy -
Selecting data from two tables
I am trying to select data from two tables. The only problem that I am running into, is that i am only seeing results from my 'uploads' table. there is also a record in documents where user = 1 that should show up. here is my sql:
$userIDNum = 1;
$sql="Select *
from uploads, documents
WHERE uploads.user = documents.user AND uploads.user = $userIDNum
ORDER BY uploads.title ASC, documents.title ASC";You'll need to explain a little more about your data and what you are trying to accomplish. Your current sql will select all columns from both the uploads and documents tables but only rows where the user id in both tables match, AND the user id equals 1. Is that not what you are seeing? Where's the code that outputs the results?
Maybe you are looking for
-
Adobe Acrobat XI Pro - Toolbar Did Not Install in Firefox
Hi, The toolbar did not install in Firefox. I'm using Firefox 31.0 on a Windows 7 Computer. I want to be able to convert webpages to pdf files and print the webpages out.
-
PO Doc Date is not Greater than MIGO Date.
Dear All, I ahve Done PO with doc date 02.02.2009 & i create MIGO as 25.01.2009 System is accepting this document. so i want restriction of this procedure. PO date is not greater than MIGO date. Thanks Shital
-
Aperture appears to have the facility to run scripts during the import stage (it's called 'Action' in the import pop up menu), but I'm having problems with it. I have successfully run the script below, and have exported the subsequent metadata to the
-
I am using Elements 8 [with a recently installed Mac IOS 10.9] and a new Epson Artisan 1430 printer . When I print 4" X 6" borderless photos, the top and bottom 1" are now cutoff in Portrait orientation and the right and left 1" are cutoff in Landsc
-
User Entry - Required on Hidden Sub-Form ?
Hi, I have a drop down list with option 'YES' or 'No' if the user selects 'Yes' then another part of my form becomes visible and it is mandatory that the user completes the fields on this form. If the user selects 'No' then they will never see the a