Load from Source-Destination=?Table structure not the same.

Hi
I have to copy data from source table to destination table. The structure of the 2 are not the same. Number of records in destination table should be half number of records in source. The reason being in the source a column named (e.g.) c_type = 'Up' - one row or 'Down' - in another row. The same is reprsented in the destination as 1 row since the number of columns is more. Example up_name, down_name, up_dep, down_dep.
How can I insert into the destination depending on the c_type column in the source?
Example:
I want to insert into destination.up_name where c_type = 'Up' and destination.down_name where c_type = 'Down'...
and so onHow can I write my sql query such that I have to write one insert statement and put the right data in the right column?

Mass25 wrote:
Number of records in destination table should be half number of records in source. The reason being in the source a >column named (e.g.) c_type = 'Up' - one row or 'Down' - in another row. The same is reprsented in the destination >as 1 row since the number of columns is more. Example up_name, down_name, up_dep, down_dep. Hope this is what you are looking for:
SQL> WITH SOURCE AS
  2       (SELECT 1 id_col, 'UP' c_type, 'up_name_1' name_col,
  3               'up_dept_1' dept_name
  4          FROM DUAL
  5        UNION ALL
  6        SELECT 1 id_col, 'DOWN' c_type, 'down_name_1' name_col,
  7               'down_dept_1' dept_name
  8          FROM DUAL
  9        UNION ALL
10        SELECT 2 id_col, 'UP' c_type, 'up_name_2' name_col,
11               'up_dept_2' dept_name
12          FROM DUAL
13        UNION ALL
14        SELECT 2 id_col, 'DOWN' c_type, 'down_name_2' name_col,
15               'down_dept_2' dept_name
16          FROM DUAL
17        UNION ALL
18        SELECT 3 id_col, 'UP' c_type, 'up_name_3' name_col,
19               'up_dept_3' dept_name
20          FROM DUAL
21        UNION ALL
22        SELECT 3 id_col, 'DOWN' c_type, 'down_name_3' name_col,
23               'down_dept_3' dept_name
24          FROM DUAL)
25  SELECT * FROM SOURCE
26  /
    ID_COL C_TY NAME_COL    DEPT_NAME
         1 UP   up_name_1   up_dept_1
         1 DOWN down_name_1 down_dept_1
         2 UP   up_name_2   up_dept_2
         2 DOWN down_name_2 down_dept_2
         3 UP   up_name_3   up_dept_3
         3 DOWN down_name_3 down_dept_3
6 rows selected.
SQL> WITH SOURCE AS
  2       (SELECT 1 id_col, 'UP' c_type, 'up_name_1' name_col,
  3               'up_dept_1' dept_name
  4          FROM DUAL
  5        UNION ALL
  6        SELECT 1 id_col, 'DOWN' c_type, 'down_name_1' name_col,
  7               'down_dept_1' dept_name
  8          FROM DUAL
  9        UNION ALL
10        SELECT 2 id_col, 'UP' c_type, 'up_name_2' name_col,
11               'up_dept_2' dept_name
12          FROM DUAL
13        UNION ALL
14        SELECT 2 id_col, 'DOWN' c_type, 'down_name_2' name_col,
15               'down_dept_2' dept_name
16          FROM DUAL
17        UNION ALL
18        SELECT 3 id_col, 'UP' c_type, 'up_name_3' name_col,
19               'up_dept_3' dept_name
20          FROM DUAL
21        UNION ALL
22        SELECT 3 id_col, 'DOWN' c_type, 'down_name_3' name_col,
23               'down_dept_3' dept_name
24          FROM DUAL)
25  SELECT s1.id_col, s1.name_col up_name, s1.dept_name up_dept,
26         s2.name_col down_name, s2.dept_name down_dept
27    FROM SOURCE s1 JOIN SOURCE s2
28         ON (s1.id_col = s2.id_col AND s1.c_type = 'UP' AND s2.c_type = 'DOWN
29  /
    ID_COL UP_NAME     UP_DEPT     DOWN_NAME   DOWN_DEPT
         1 up_name_1   up_dept_1   down_name_1 down_dept_1
         2 up_name_2   up_dept_2   down_name_2 down_dept_2
         3 up_name_3   up_dept_3   down_name_3 down_dept_3
3 rows selected.
SQL>Source had 6 records and it was self joined to give 3 records which can be populated in Destination Table.
Always post some sample data with desired result. That will get you quick responses.
Regards,
Jo
Edited: Added Quote Tags

Similar Messages

  • How do I reference cells from a different table/ sheet in the same document

    Say I have a Sheet that contains two Tables: [A] and . Is it possible to cross-reference the content of a cell in Table [A] from Table and use it to create a function in Table ?
    Eg: =SUM[TableA(K20)]+[TableB(F20:F50)]
    Could I similarly cross-reference the content of cells in Tables in different Sheets?
    Thanks,
    Seb

    Seb,
    Yes, you can. With the cursor in the location where you want to place the external reference, navigate to your Sheet and Table of choice and click the cell that you wish to reference. The external reference will appear in the formula.
    Note however that we are talking about different sheets in the same Numbers file. We can't reference sheets or tables in other files.
    Jerry
    Message was edited by: Jerrold Green1

  • How to summary a field from 2 separate tables but having the same fields

    Post Author: thuyvd78
    CA Forum: General
    Hi, I am getting trouble with creating the summary from 2 separate tables. These tables dont have any link together but they have the same fields, such as: part id, qty, etc. I need to create a report that displays whole the information from these tables and also the summary of total qty field of these tablesAny idea to organize this report? Thank you very much! Thuy  

    Post Author: thuyvd78
    CA Forum: General
    Thank you for your help v361.where can I can get the link to download samples for subreport from official website?And can I use FULL INNER query to join these tables. I think this way is much clearer than using subreport but not sure it will work? Thanks Thuy  

  • Pushed contacts from gmail on iPhone 4 not the same as iPhone 3G

    Hi
    I use gmail (via Microsoft Exchange setting on the iphone) to push all of my contacts from gmail onto my iPhones contacts and this worked great on my iPhone 3G.
    However, since upgrading to an iPhone 4, whenever I add a new contact on my iPhone, the new contact isn't pushed to my list of gmail contacts when I sign in to gmail to check.
    What I have found is that if I back out of all contacts and into groups, there is now a tab called "On my iPhone" and when I hit this I see the contacts that I have added from my iPhone. I want it to go back to the way it was before and for it to be that every time I add a new contact on my iPhone, I want it to be added to my gmail contacts and not on it's own just on the iPhone.
    How can this be resolved please?

    The U.S. Apple store publicized as the type of Sim-free iPhone, and not as a contract-free.
    Now in the Apple store site, including the FAQ for purchasing iPhone4 unloked, is written:
    http://store.apple.com/us/product/MC603LL/A?mco=MjI4NTM2NTM
    "Why does the price of the unlocked iPhone differ from the price of a contract-based iPhone?
    Carriers typically subsidize the purchase price of the phone when purchased with a service contract. By purchasing your iPhone unlocked, you are not committing to a service contract up front, so you can use any micro-SIM card from a supported GSM carrier, including your current one"
    I wonder why I pay the same price as a phone but an identical unlocked, it is a fraud

  • New Computer, trying to use Itunes from old laptop they are not the same account... help?

    Hello all. I had a laptop with Itunes to which I had my Ipad, IPhone and External Hard Drive with 80GB of music, etc., synced. Now I installed Itunes on my new computer (runnning Windows 8) and it does not have the same items as my laptop?!?!

    See also this migrate iTunes library post.
    tt2

  • Number of query values and destination fields are not the same.

    Hey can any one help me out with this. I have no idea where i'm going wrong.
    String query_beg="insert into [insert$] values('"+rs1.getString("USERID")+"','"+rs1.getString("NAME")+"','"+beg_1+"','"+beg1_1+"','"+rs1.getTime("LOGINTIME")+"','"+rs1.getString("CLIENT_TIMEZONE")+"')";
    int num = stmnt2.executeUpdate(query_beg);Thanks in advance!
    Cheers

    I think it�s missing some field in your values

  • Insert data into fact table from source database tables

    here i try to insert data into fact table from source database tables here is the query 
    ALTER procedure [dbo].[facttable]
    as
    insert into [pp dw].dbo.Dimfact(Prod_ID,Production_ID,Material_ID,Equip_ID,WC_ID,Recipe_ID,Quantity,costprice)
    select Products.[Product ID],[Production ID],Materials.[Material ID],[Equipment ID],[Work Centre ID],[Recipy ID],Quantity,[cost price]
    from
    [PRODUCTION PLANNING 2].dbo.[Products],
    [PRODUCTION PLANNING 2].dbo.[Production Detail],
    [PRODUCTION PLANNING 2].dbo.[Material category],
    [PRODUCTION PLANNING 2].dbo.[Materials],
    [PRODUCTION PLANNING 2].dbo.[Equipment],
    [PRODUCTION PLANNING 2].dbo.[Working Centre] ,
    [PRODUCTION PLANNING 2].dbo.[Recipies]
    where
    Products.[Product ID] in (13, 14, 15, 16, 17) and
    [Production Detail].[Production ID] in (1, 2, 3) and
    [Materials].[Material ID] in (1, 2, 3, 4, 5) and
    [Equipment].[Equipment ID] in (1, 2, 3, 4) and
    [Working Centre].[Work Centre ID] in (1, 2, 3) and
    [Recipies].[Recipy ID] in (1, 2, 3) and
    [Material category].[Category ID] in (8, 9, 10, 11, 12, 13)
    and when i execute query it shows me error 
    The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Dimfact_Dimproduct". The conflict occurred in database "pp dw", table "dbo.Dimproduct", column 'Prod_ID'.
    ERD IS
    HOW TO SOLVE THIS PROBLEM?

    I cant see any join conditions in your query posted. Whats the purpose of the query above. It will just bring you a cartesian product (cross join) of tables involved subjected to filters. Are you sure this is the correct query?
    The error you're getting may be because you've not yet populated DimProduct or may be because of logic you used in popultaing DimProduct causing it to miss some records which is what query is referring to in above case.
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Data Load from Source to Destination

    Hello Forum Members,
    I have to databases on different solaris servers.
    I have to load data from Source Table[Server 1] to Target Current Table[truncate existing data and load from Source Table] [Server 2]and on every Wednesday from Target Current Table into Target History Table[Data always appended][Server 2].
    Any advice how to solve the issue is highly appreciated.
    Thanks and Regards,
    Suresh

    Unless there is a history table on the remote server, the history table would not appear to be an appropriate candidate for a materialized view.
    You could, in theory, create the live table as a materialized view rather than doing a TRUNCATE (or DELETE) and INSERT INTO SELECT in your stored procedure. Since it sounds like you need to have some coordination between the refreshing of the materialized view and the population of the history table, it's not obvious that creating the live table as a materialized view buys you anything.
    Justin

  • How to force BI Server to pick from the Agg table and not the Fact table?

    Hi All,
    I have 3 tables as the Sources in the Key measures. 2 are fact tables and the other one is the agg table.
    E.g.
    Fact 1 at A,B,C,D and E level
    Fact 2 at A,B,C level
    Agg at A,B,C level which contains the measures from the Fact1 and Fact2
    So when I select the measures from the Agg which are coming from Fact1 the Agg table get fired and when I select measures from Agg which are coming from Fact2, the Fact2 table gets fired in the SQL Query.
    Now my question here is there anyway to tell BI Server that when I select Fact2 measures fire the Agg table and not the Fact2 table. The reason being the Agg and Fact2 tables are at the same level.
    But I need to keep the Agg table as it is one level higher than the Fact1 tables.
    Any pointers would be helpful.

    hi,
    you explain us your situation really good.but you forgot to tell us the most import,the measures in aggregate table and the aggregated dimensions.
    meaning,you have 7 measures aggregated in some levels of your dimensions tables?if yes,there is no possibility Bi goes anywhere else..(by choosing only these measures and the defined levels at your dimensions..)
    One more thing,if you choose a combination of your 2 fact data sources,bi goes?where???
    hope i helped...
    http://greekoraclebi.blogspot.com/

  • Doesn't load from source system to PSA and DSO

    Hi Gurus,
    We have launched a Delta load from Source System (POSDM) to DSO. In the source system there are 5000000 rows but none was loaded into DSO or PSA. The delta load was ok, but any data was loaded.
    If the delta  load was lunch again, would be loaded those 5000000 rows. Or those 5000000 rows wouldn't be able to load again.
    Any idea abut this issue? Any feedback will be really appreciated.
    Thanks in advance.

    Hi David,
    Are you sure this 5 million records are delta records and should be pulled into BW as delta??
    did you count the number of records in the underlying tables??
    which data source you are using??
    Delta loads are suppose to bring the new records or changed records since the last data load and not all the records.
    Since the request is green as you said and still it shows 0 records then it is possible that nothing has changed since last delta.try to see the details of the data load... if it failed...may be thats the reason you are not able to see any records.
    If you schedule the delta again it will bring the records changed or created after last delta.
    If the delta was unsuccessfull then turn the QM status and overall status of request to red manually in the monitor of the request and delete it from PSA and all the targets in which its loaded and schedule the delta again and it should bring the delta.
    Thanks
    Ajeet
    Thanks
    Ajeet

  • Open Hub Destination table structure update

    Hi,
         I created a open Hub detsination and activation created the table  and populated the data in the table and have a view over the table.
         I need to add few more fields in the open hub and when I did that and activated again , it is supposed to change the table structure adding the new fields that were added in the open hub.
       The activation was successful but the table structure still stays the same.I didn't see the new fields in the generated table.
       Anyone having similar issues.
      Thanks in advance

    We deleted all the related objects from Staging and production and re transported them from Development as though they are being sent for the first time and that works.Tough this approach is not good we need to use it as I didn't find any other solution

  • Simpli Home Artisan : TV Stand and Coffee Table : Not the same color. HELP

    Hello,
    I ordered and received the Simpli Home Artisan TV Stand from the BestBuy website.  We got it a couple weeks ago, put it together and love it.
    We decided to order the matching Simpli Home Artisan Coffee table to go with it.  We just picked it up today and it is not the same color at the TV stand.
    Both item listed on the BestBuy website say they are "Medium auburn brown" in color, as do the boxes we recieved. However they are not the same color, the TV stand is much darker than the coffee table.
    TV Stand: http://www.bestbuy.com/site/simpli-home-artisan-tv-stand-for-most-flat-panel-tvs-up-to-54/1622137.p?...
    Coffe Table: http://www.bestbuy.com/site/simpli-home-artisan-collection-coffee-table/1860306.p?id=1219066204317&s...
    If you go to the Simpli Home manufacturer website you will see that Artisan collection comes in two different color tones, "Available in Auburn or Tobacco Brown".
    Simpli Home Website: http://www.simpli-home.com/#!wood---artisan-coffee-table/cuhk
    The TV stand we got is Tobacco Brown, and though the color does not match the pictures on BestBuy.com, we liked it and decided it was okay, but not if the coffee table doesn't match.
    I really don't care if I get Tobacco Brown or Medium Auburn, I just want them to match.  However since I've already assembled the TV Stand, I would like to return the coffee table and get one that is Tobacco brown.
    I posted this to the forum because I know if I call the store they won't have a clue what I am talking about.
    Please let me know what I should do, and help me if you can.
    Thank you
    Solved!
    Go to Solution.

    Greetings rtb1980,
    I can definitely understand why you would choose both of those pieces of furniture as they look wonderful, but of course it would be a chronic annoyance if the furniture didn’t match. Using the email address you registered with the forum, I was able to take a look at your purchase history and the items on our site as well as the manufacturer’s.
    As we get all of our information about the products directly from the manufacturer, it would seem that you received the wrong color TV stand, and that you would have received the correct color for the coffee table. As these items are special ordered items, meaning the orders are not fulfilled directly by us, it is difficult to say where the mix up may have occurred with your TV stand, for which I am truly sorry.  
    That being said, it does not appear that we carry the coffee table in the tobacco brown color you are looking for. Sadly, this means we would be unable to provide you an exchange for the tobacco color, although you should be able to return the coffee table within the Return & Exchange Policy. However, we should be able to provide you with an exchange of your TV stand for the correct color to match the auburn colored coffee table you received; although, I understand that this may not be the ideal resolution, as it may have been the more complicated piece of furniture to put together.
    I apologize for any inconvenience this experience may have caused you. If you should have any questions, or need any further assistance, please do not hesitate to reach out to me.
    Sincerely,
    Tasha|Social Media Specialist | Best Buy® Corporate
     Private Message

  • RFC Error:The BW IDoc type ZSBA011 is not the same as the source system

    Hi Experts,
    RSA1Source System (Context Menu) Check
    I am getting the below error
    <b>‘The BW IDoc type ZSBA011 is not the same as the source system  IDoc type ZSBD012 ‘              </b>                              
    What might happened wrong.When i checked with my Basis Consultant who is new to job,Replied every this is ok with regeards to RFC.
    Where should i check to correct the error
    Thanks

    Hi,
    Did you do a system copy for BW ?
    Try a restore (rightclick on your source system) in most cases this will solve the problem.
    If not check the notes below:
    184322  Procedure after DB copy of BW source systems 
    886102      System Landscape Copy for SAP BW 2.X, 3.X and NW2004s BI
    325470      Activities after client copy in BW source systems
    325525      Copying and renaming systems in a BW environment
    184754      Procedure after BW database copy
    184447      Building a BW-system landscape
    184971      Notes on BW source system connections
    140276      Error in source system assignment
    524554      Storing destinations in the BW environment
    538052  Maintenance of Myself destination in BW
    Regards, Patrick Rieken
    Message was edited by:
            Patrick Rieken - BI-Formance B.V.

  • BI  IDOC type ZSBS042  is not the same as source system idoc type ZSBM023.

    Hi  Evrybody,
    I got an error when trying to initialize the delta load.
    Error Message :
    BI  IDOC type ZSBS042  is not the same as source system idoc type ZSBM023.
    Thanks for  the promt responses
    Regards,
    Zakir SM

    Hi ,
    I checked the IDOC with status 51.. I have this message
    " No status record was passed to ALE by the application ".
    what to do now...
    Rgds,
    Zakir

  • FaceTime: I have a iPad, iPhone, iMac all on the same apple Id/account. Without changing id/email address can I use FaceTime between any 2 of my devices? It works from iPad to iPhone but not the other way??? I would like talk/see my kids if am away

    FaceTime: I have a iPad, iPhone, iMac all on the same apple Id/account. Without changing id/email address can I use FaceTime between any 2 of my devices? It works from iPad to iPhone but not the other way??? I would like talk/see my kids if am away.
    Hope you can help.
    I have added a new email address but kept my Id, but I get busy when trying from iPhone to iPad as they are clashing. Like find my iPhone app hence trying to keep them all on one account

    IOS: using facetime http://support.apple.com/kb/ht4319
    using an ipad will use the email address since you can't make a phone call.  see the link.
    Your basically calling/emailing yourself that's why your getting a busy signal.

Maybe you are looking for

  • About selecting single column in a alv table.........

    Hi Experts, I need single column to be selected from a ALV table...selected in da sense to be highlighted....as it happens..by default for a row..... I hope u understood my query... Please help me out in this.. I know u all will surely help me... Thk

  • Apple acounts

    If I signed from two different apple ID on my phone, and now my Icloude is not working?? because whenever I tried to sign in the device alert me that there is too many apple ID on the Iphone? I need to know how I can delete the Apple ID for good??

  • Why are so many songs duplicated in my library?

    Just recently lost hard drive to failure.  Replaced drive and reloaded ITunes.  Now I have many many songs that are duplicated in my library.......almost all of them!  Does this mean that I have duplicates in my ITunes music folder, or that I have mo

  • Image file access dates changing in mass (Windows).

    In review of the access date properties for image files within a directory being accessed by Bridge within the Favorites area, they are all changing to the current time and date, even if the image is not viewed within Bridge.  Why are the access date

  • I lost the ability to download and view video on my mac, how do I restore this functionality?

    I lost the ability to download and view video on my Mac. How do i restore that functionality?