Fetch Data from two Database
I want to fetch data from two tables which are in two separate database. Is it possible to fetch similar from two schemas of same database.
Pls help with query.
Hi,
Say you have two schema S1 and S2 in the same database 'xyz' then you can create two database links to these two schemas from any third schema as ::
CREATE database link s1link connect to S1 identified by <password of S1> using 'xyz' ;
CREATE database link s2link connect to S2 identified by <password of S2> using 'xyz' ;
Now say if there is a table called tab1 in schema S1, then you can get data from it as ::
SELECT T1.*
FROM tab1@s1link T1
WHERE < you can put conditions here> ;
Similarly for the columns of a table of schema S2.
- Thanks
Sandipan
Similar Messages
-
FETCH DATA FROM ORACLE DATABASE USING Web Dynpro
I want to fetch data from ORACLE database using Web Dynpro.How can I do this?
1) Are you sure that you get no results? It sounds like you are having name resolution issues, which would imply that you should be getting an ORA-00942 error indicating that the table doesn't exist (or that you don't have access to the table). If you are not seeing this error, I would tend to suspect an overzealous exception handler.
2) What database account owns the table? What database account is your ASP.Net application using to connect? Assuming these two accounts are different, your application would either have to
- Explicitly prefix the table name with the schema name
- Have a public or private synonym that maps the table name to the fully qualified identifier schema_name.table_name
- Issue the command ALTER SESSION SET CURRENT_SCHEMA = <<schema name>> in each session, in which case all queries in the session would use the specified schema name as the default if no schema name is prefixed.
Justin -
How to fetch data from single database table using 2 internal tables.
Hi friends,
i am a new user of ABAP and also SDN.
i need a help.
i want to fetch data from one database table based on primary keys of 2 internal tables. how to put in where clause.
Thanks in advance.hii
refer to following code ..i hope it will help you
SELECT matnr " Material Number
FROM mara
INTO TABLE i_mara
WHERE matnr IN s_matnr.
IF i_mara[] IS NOT INITIAL.
SELECT matnr " Material Number
werks " Plants
prctr " Profit Center
FROM marc
INTO TABLE i_marc
FOR ALL ENTRIES IN i_mara
WHERE matnr = i_mara-matnr
AND werks IN s_werks.
ENDIF. " IF i_mara[] IS NOT INITIAL
i_output = i_marc.
IF i_marc[] IS NOT INITIAL.
SELECT matnr " Material Number
werks " Plants
lgort " Storage Location
FROM mard
INTO TABLE i_mard
FOR ALL ENTRIES IN i_marc
WHERE matnr EQ i_marc-matnr
AND werks EQ i_marc-werks
AND lgort IN s_lgort.
ENDIF. " IF i_mara[] IS NOT INITIAL
regards
twinkal -
Get data from two databases?
Hello all,
Do anyone know if it's posible to get data from two databases while I'm running SBO in one of them? I need this because our client wants to be able to print reports with all the information stored in both companies. I searched this forum trying to find if this is possible but I did't find any information about this.
Can someone help me?
Thanks and regards,
Mariana MazzeroHi Mariana,
What you can do is use two company objects to retrieve the data. As far as I know you're not restricted to one company connection.
You can also just use a standard read only connection (like ADO/ODBC) to retrieve the data for the reports.
Hope it helps,
Adele -
To fetch data from Oracle Database
Hi Gents,
Any alternative option other than SQL to fetch data from Oracle DAtabase. ( My manager worked on Mainframes he is telling other than SQL there should be some options.. Gents pls guide if any options.......
REgards
Fento>
Any alternative option other than SQL to fetch data from Oracle DAtabase. ( My manager worked on Mainframes he is telling other than SQL there should be some options.. Gents pls guide if any options.......
>
There is no other (supported) way to get data from Oracle Databases as SQL. No matter what third-party tool you use to access Oracle Databases, they all will use (embedded) SQL.
In very rare cases, one must use tools to read from datafiles directly because the database got damaged and a proper recovery is impossible. That is an emergency solution and by no means a replacement for SQL access.
In short: No :-)
Kind regards
Uwe
http://uhesse.wordpress.com -
Fetch data from different database tables
Hi...
How can i fetch data from different database tables and put it into a internal table and then display it??? Can provide simple short codes as i'm new to ABAP. Thanks.Hi,
Check this sample code..
TYPE-POOLS: slis.
DATA: BEGIN OF itab OCCURS 0,
vbeln TYPE vbeln,
expand,
END OF itab.
DATA: BEGIN OF itab1 OCCURS 0,
vbeln TYPE vbeln,
posnr TYPE posnr,
matnr TYPE matnr,
netpr TYPE netpr,
END OF itab1.
DATA: t_fieldcatalog TYPE slis_t_fieldcat_alv.
DATA: s_fieldcatalog TYPE slis_fieldcat_alv.
s_fieldcatalog-col_pos = '1'.
s_fieldcatalog-fieldname = 'VBELN'.
s_fieldcatalog-tabname = 'ITAB'.
s_fieldcatalog-rollname = 'VBELN'.
s_fieldcatalog-outputlen = '12'.
APPEND s_fieldcatalog TO t_fieldcatalog.
CLEAR: s_fieldcatalog.
s_fieldcatalog-col_pos = '1'.
s_fieldcatalog-fieldname = 'VBELN'.
s_fieldcatalog-tabname = 'ITAB1'.
s_fieldcatalog-rollname = 'VBELN'.
s_fieldcatalog-outputlen = '12'.
APPEND s_fieldcatalog TO t_fieldcatalog.
CLEAR: s_fieldcatalog.
s_fieldcatalog-col_pos = '2'.
s_fieldcatalog-fieldname = 'POSNR'.
s_fieldcatalog-tabname = 'ITAB1'.
s_fieldcatalog-rollname = 'POSNR'.
APPEND s_fieldcatalog TO t_fieldcatalog.
CLEAR: s_fieldcatalog.
s_fieldcatalog-col_pos = '3'.
s_fieldcatalog-fieldname = 'MATNR'.
s_fieldcatalog-tabname = 'ITAB1'.
s_fieldcatalog-rollname = 'MATNR'.
APPEND s_fieldcatalog TO t_fieldcatalog.
CLEAR: s_fieldcatalog.
s_fieldcatalog-col_pos = '4'.
s_fieldcatalog-fieldname = 'NETPR'.
s_fieldcatalog-tabname = 'ITAB1'.
s_fieldcatalog-rollname = 'NETPR'.
s_fieldcatalog-do_sum = 'X'.
APPEND s_fieldcatalog TO t_fieldcatalog.
CLEAR: s_fieldcatalog.
DATA: s_layout TYPE slis_layout_alv.
s_layout-subtotals_text = 'SUBTOTAL TEXT'.
s_layout-key_hotspot = 'X'.
s_layout-expand_fieldname = 'EXPAND'.
SELECT vbeln UP TO 100 ROWS
FROM
vbak
INTO TABLE itab.
IF NOT itab[] IS INITIAL.
SELECT vbeln posnr matnr netpr
FROM vbap
INTO TABLE itab1
FOR ALL ENTRIES IN itab
WHERE vbeln = itab-vbeln.
ENDIF.
DATA: v_repid TYPE syrepid.
v_repid = sy-repid.
DATA: s_keyinfo TYPE slis_keyinfo_alv.
s_keyinfo-header01 = 'VBELN'.
s_keyinfo-item01 = 'VBELN'.
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
i_callback_program = v_repid
is_layout = s_layout
it_fieldcat = t_fieldcatalog
i_tabname_header = 'ITAB'
i_tabname_item = 'ITAB1'
is_keyinfo = s_keyinfo
TABLES
t_outtab_header = itab
t_outtab_item = itab1
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Thanks
Naren -
What is best method to retrieve data from two databases
I'm writing a report that needs data from two sql databases. Not the same brand. Grouping and sorting fields come from both databases, so I can't just read one and retrieve data from the other. It seems to me I have to extract data from each data base using crystal reports, merge the two files using crystal reports and feed the merged file into crystal reports. I've not found a simpler or better method in the Crystal Reports documentation. Is there documentation about doing this process on the web site or with crystal reports documentation? My method seems cumbersome so I'm wondering if there is a better method.
Jeffrey,
A cheap and effective solution, for a periodic transfer would be using XML.
If you have the DDL for all of the objects in the database, you can just duplicate it on whatever RDBMS engine you want, and then, extract the data, table per table into XML files from the target server, and then load the files into the target server.
Otherwise, if you are going to do this in an ongoing basis, then, use SAP Replication Server. The best asynchronous, real time, heterogeous replication solution in the industry, exploited with a great deal of success by many critical mission financial applications with global topologies and sub second latency.
My two cents.
I hope they help.
Regards,
Jean-Pierre -
To fetch Data from multiple database tables!
How to fetch Data from fields of multiple database tables!
Give me one example!use <b>join....</b>
c the SAPHELP docs...
FROM tabref1 [INNER] JOIN tabref2 ON cond
Effect
The data is to be selected from transparent database tables and/or views determined by tabref1 and tabref2. tabref1 and tabref2 each have the same form as in variant 1 or are themselves Join expressions. The keyword INNER does not have to be specified. The database tables or views determined by tabref1 and tabref2 must be recognized by the ABAP Dictionary.
In a relational data structure, it is quite normal for data that belongs together to be split up across several tables to help the process of standardization (see relational databases). To regroup this information into a database query, you can link tables using the join command. This formulates conditions for the columns in the tables involved. The inner join contains all combinations of lines from the database table determined by tabref1 with lines from the table determined by tabref2, whose values together meet the logical condition (join condition) specified using ON>cond.
Inner join between table 1 and table 2, where column D in both tables in the join condition is set the same:
Table 1 Table 2
A
B
C
D
D
E
F
G
H
a1
b1
c1
1
1
e1
f1
g1
h1
a2
b2
c2
1
3
e2
f2
g2
h2
a3
b3
c3
2
4
e3
f3
g3
h3
a4
b4
c4
3
|--|||--|
Inner Join
|--||||||||--|
| A | B | C | D | D | E | F | G | H |
|--||||||||--|
| a1 | b1 | c1 | 1 | 1 | e1 | f1 | g1 | h1 |
| a2 | b2 | c2 | 1 | 1 | e1 | f1 | g1 | h1 |
| a4 | b4 | c4 | 3 | 3 | e2 | f2 | g2 | h2 |
|--||||||||--|
Example
Output a list of all flights from Frankfurt to New York between September 10th and 20th, 2001 that are not sold out:
DATA: DATE LIKE SFLIGHT-FLDATE,
CARRID LIKE SFLIGHT-CARRID,
CONNID LIKE SFLIGHT-CONNID.
SELECT FCARRID FCONNID F~FLDATE
INTO (CARRID, CONNID, DATE)
FROM SFLIGHT AS F INNER JOIN SPFLI AS P
ON FCARRID = PCARRID AND
FCONNID = PCONNID
WHERE P~CITYFROM = 'FRANKFURT'
AND P~CITYTO = 'NEW YORK'
AND F~FLDATE BETWEEN '20010910' AND '20010920'
AND FSEATSOCC < FSEATSMAX.
WRITE: / DATE, CARRID, CONNID.
ENDSELECT.
If there are columns with the same name in both tables, you must distinguish between them by prefixing the field descriptor with the table name or a table alias. -
SELECT data from two databases
I have two databases that I need to select data from in a
single SELECT. Using DWs Advanced window for creating the select I
don't see any way to select more than 1 Connection. Both databases
have unique user and passwords but reside on the same server. Any
idea how I can write a single SELECT to get data from both dbs. I
assumed it would be similar to selecting data from multiple tables
within the same db but the connection part is stumping me. Any
ideas would be greatly appreciated.TouchstonePress wrote:
> Page 48, Developing a Web Database Application . . .
speaks about making a
> database with two related TABLES each with the same
PRIMARY KEY column with
> which to identify a customer using their unique number.
That's the basic technique for joining two tables in the same
database.
The original poster has tables in different databases that
have
different user accounts and passwords.
Although it's possible to join two databases, you cannot do
it unless
you have one user account with the same privileges on both
databases.
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of
ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/ -
Hi friends,
I've two similar tables A and B with one more column in table B that is "Active Flag".
Table A
Rowid----Fname----Lname
101-----AF1----------AL1
102----AF2-----------AL2
103-----AF3---------AL3
104-----AF4---------AL4
Table B
Rowid-----Fname---Lname---Flag
101-----BF1----------BL1--------Y
102-----BF2----------BL2---------N
103-----BF3----------BL3--------N
104-----BF4----------BL4-------Y
I need to fetch data in Table C with column rowid, Fname and Lname.
If Flag is Y in Table B, this record should come to table C otherwise the record from table A will come to C. Rowid is the primary key.
Table C should be like this..
Rowid-----Fname---Lname
101-----BF1----------BL1
102-----AF2----------AL2
103-----AF3----------AL3
104-----BF4----------BL4
Thanks in advanceHi,
try this
QL> With T As
2 (
3 Select 101 Id, 'BF1' fname, 'BL1' lname, 'Y' flag
4 From DUAL
5 Union All
6 Select 102, 'BF2', 'BL2', 'N'
7 From DUAL
8 Union All
9 Select 103, 'BF3', 'BL3', 'N'
10 From DUAL
11 Union All
12 Select 104, 'BF4', 'BL4', 'Y'
13 From DUAL),
14 T1 As
15 (
16 Select 101 Id, 'BF1' fname, 'BL1' lname
17 From DUAL
18 Union All
19 Select 102, 'AF2', 'AL2'
20 From DUAL
21 Union All
22 Select 103, 'AF3', 'AL3'
23 From DUAL
24 Union All
25 Select 104, 'BF4', 'BL4'
26 From DUAL)
27 Select T1.Id, T1.fname, T1.lname
28 From T, T1
29 Where T.Id = T1.Id
30 And T.flag='Y'
31 /
ID FNA LNA
101 BF1 BL1
104 BF4 BL4and rowid is oracle reserved word. you should be aware of oracle reserved word, kindly refer this v$reserved_words
Edited by: user291283 on Sep 7, 2009 10:18 PM -
Is it possible to get data in one report
from two different database(Oracle,Sybase)
Thank You<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by nirali:
Is it possible to get data in one report
from two different database(Oracle,Sybase)
Thank You<HR></BLOCKQUOTE>
Check www.attunity.com Attunity Connect does that - hetrogenous joins
null -
Fetching data from a database to a JTable
Can anyone please help me out in this topic. I have created an application in NetBeans 5.5.1 which has a table with only the same columns names as the database,but has null data values. Now I want that on click of a "Search" button the data will be fetched from the database and sorted out in the table under the respective column names. I really need help on this one.
In the future, Swing related questions should be posted in the Swing forum.
What keywords did you use to search the forum before you posted? Keywords like "jtable resultset" should find other postings on this topic. I've posted a solution in the Swing forum so you could also add my id to the keyword list if you want. -
Fetch data from two tables and insert into one table
I have similar to the following data in two tables (@Plant, @PlantDirector) and need to consolidate into one table (@PlantNew) as follows.
DECLARE @Plant TABLE (PlantID INT, PlantName VARCHAR(100))
INSERT INTO @Plant (PlantID, PlantName) VALUES (1, 'Name One'),(2, 'Name Two'),(3, 'Name Three'),(4, 'Name Four'),(5, 'Name Five'),(6, 'Name Six')
Director data for the Plants exist in the following table. Assistant value 1 means Assistant Director and 0 means Director.
Data exists only for subset of plants and a Plant may have one or both roles.
DECLARE @PlantDirector TABLE (PlantID INT, PlantDirectorID INT, Assistant bit)
INSERT INTO @PlantDirector (PlantID, PlantDirectorID, Assistant) VALUES (2, 111, 1),(2, 222, 0),(4, 333, 0),(6,444,1)
The above data needs to be inserted into one table (@PlantNew) as follows:
PlantID in @Plant table is IDENTITY value and needs to be inserted as-is into this table.
PlantDirExists will get a value of 1 if at least one record exists in @PlantDirector table for a PlantID. PlantAssistantDirID and PlantDirID should be set to the corresponding PlantDirID or NULL appropriately depending on the data.
DECLARE @PlantNew TABLE (PlantID INT, PlantName VARCHAR(100), PlantDirExists bit, PlantAssistantDirID INT, PlantDirID INT)
INSERT INTO @PlantNew (PlantID, PlantName, PlantDirExists, PlantAssistantDirID, PlantDirID)
VALUES (1, 'Name One', 0, NULL, NULL),(2, 'Name Two', 1, 111, 222),(3, 'Name Three', 0, NULL, NULL),(4, 'Name Four', 1, NULL, 333),(5, 'Name Five', 0, NULL, NULL),(6, 'Name Six',1, 444, NULL)
How do I achieve the above using SQL ? Thanks.like this
INSERT @PlantNew (PlantID, PlantName, PlantDirExists, PlantAssistantDirID, PlantDirID)
SELECT p.PlantID,
p.PlantName,
CASE WHEN pd.PlantID IS NULL THEN 0 ELSE 1 END,
PlantAssistantDirID,
PlantDirID
FROM @Plant p
LEFT JOIN (SELECT PlantID,
MAX(CASE WHEN Assistant = 1 THEN PlantDirectorID END) AS PlantAssistantDirID,
MAX(CASE WHEN Assistant = 0 THEN PlantDirectorID END) AS PlantDirID
@PlantDirector
GROUP BY PlantID)pd
ON pd.PlantID = p.PlantID
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
You're missing a FROM
insert into @PlantNew
SELECT p.PlantID,
p.PlantName,
CASE WHEN pd.PlantID IS NULL THEN 0 ELSE 1 END,
PlantAssistantDirID,
PlantDirID
FROM @Plant p
LEFT JOIN (SELECT PlantID,
MAX(CASE WHEN Assistant = 1 THEN PlantDirectorID END) AS PlantAssistantDirID,
MAX(CASE WHEN Assistant = 0 THEN PlantDirectorID END) AS PlantDirID
from @PlantDirector
GROUP BY PlantID)pd
ON pd.PlantID = p.PlantID -
Fetch Data from two different Lists (Based on criteria)
I have two lists. One is for Designations and another is for
Hirings. Designations list holds all available designations and Hiring list has list of hired employees. Data may look like following...
Designations list:
PostTitle
Software Engineer
Web Developer
Graphic Designer
Trainer
Manager
Team Lead
and Hiring list may look like following
Hirings list:
PostTitle
Employee
Start Date End Date
Trainer David
05-Jun-14
Manager Peter
06-Jun-14 30-Jun-14
PostTitle is lookup column in hirings list. Now, I have to create several views over this data... one of them is of "Vacant Posts" that will fetch all those records from Designations which are either not referenced in hirings or are referenced
in hirings but has some end date.
Vacant Posts View:
Fetch all records from Designation which are NOT in Hirings
UNION
Fetch all records from Designations which are in Hirings But has some END DATE.
Please guide me how can I create this Vacant Posts view ? Is their any out of the box functionality available ? what are the easiest possible ways to accomplish this?
Zia.Yes You can Use CAML.
Below Query can be helpful to start with.
Function GetSharePointList1() {
context = SP.ClientContext.get_curre
nt();
oList = context.get_web().get_lists().getByTitle('SharePoint List 2');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(query);
items = oList.getItems(camlQuery);
context.load(items);
context.executeQueryAsync(
Function.createDelegate(this, onSuccessSharePointList1),
Function.createDelegate(this, onFail)
function onSuccessSharePointList1(){
recNum = items.get_count();
if(recNum != 0){
var listItemEnumerator = items.getEnumerator();
while(listItemEnumerator.moveNext()){
var oListItem = listItemEnumerator.get_current();
$().SPServices({
operation: "GetListItems",
async: false,
listName: "SharePoint List 2",
CAMLViewFields: "<ViewFields><FieldRef Name='Worklocation'/></ViewFields>",
CAMLQuery: "<Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>" + ReferenceID +
"</Value></Eq></Where></Query>",
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function() {
Worklocation = ($(this).attr("ows_Worklocation"));
s = ..... (display all in table format)
$("#resultTable").append(s);
i++;
Thanks and Regards Rahul Dagar -
5 months rolling monthly report by fetching data from cache & Database
Scenario: One monthly report would be created each month end which contains one summary tab and other details tabs. Summary tabs will contain the data of all the months summary data (current month and previous months)
Problem:
Current month data have to come directly from database and previous months data come form cache and whole thing will be cached this time so that when we run next month report the data till this month will also come from cache.
Any one please help me ASAP.What's wrong with F_GET_COMPANY_CODE ? Below is similar code - try running this and seeing what you get:
report zlocal_jc_t001w.
tables:
t001k, "Valuation area
t001w. "Plants/Branches
parameters:
p_bukrs like t001k-bukrs default '1000'.
select-options:
s_werks for t001w-werks.
start-of-selection.
perform get_data.
*& Form get_data
form get_data.
data:
begin of gt_t001k occurs 10,
bukrs like t001k-bukrs,
bwkey like t001k-bwkey,
werks like t001w-werks,
end of gt_t001k.
select
t001k~bukrs
t001k~bwkey
t001w~werks
into corresponding fields of table gt_t001k
from t001k as t001k
inner join t001w as t001w on t001w~bwkey = t001k~bwkey
where t001k~bukrs = p_bukrs
and t001w~werks in s_werks.
loop at gt_t001k.
write: /
gt_t001k-bukrs,
gt_t001k-bwkey,
gt_t001k-werks.
endloop.
endform. "get_data
As for links to locally defined database tables, that will depend on what the keys defined in SE11 are e.g. there will be a primary key plus relationships to other tables (for example "WERKS LIKE YSDA_EXP_PRTLOG-YY_PLANT" indicates YY_PLANT relates to T001W).
Jonathan
Maybe you are looking for
-
Excise Invoice with reference to Commercial Invoice
Hello Experts My client has third party software. In SD- Order to Invoice cycle is done in that software. After Invoice is created the data is interfaced and Invoice is received in SAP. Now my doubt is that will it be possible to create the excise in
-
Apple Lossless Tags won't Save
Hi everyone, Has anyone experienced this? I have about 4 CDs that I've ripped in iTunes (I think), and they are all in Apple Lossless m4a. Despite the fact that their tags load just fine in other programs, iTunes is treating these files as if they ha
-
Changing slide size in Cap 5 handouts?
Hi, I have published Cap 5 projects as handouts, both with and without tables. Without the tables, I can only get one slide per page--but if I include tables, the slides shrink dramatically (even if I only select 2 slides per page). I have looked at
-
I'm using FusionDisplay to get a taskbar for my second monitor, and the taskbar has worked well until now. Now when I open pinned Aurora, it opens a new application and doesn't merge with the pinned down application icon. It seems to locate the Firef
-
Error In ccBPM : Correlation Error
Hi All, We are working on a scenario where in the first received structure in ccBPM waits second structure using correlation. And further we need to merge both of them together using transformation (Message Mapping) inside ccBPM . Interestingly in ou