Convert data from table1 to another table

table1 is the source table, i want to create a command button to generate a query, convert and separate the data into table2
here are the conditions:
1. only data contains "MMHK" in either 1stdest or 2nddest fields
2. if 1stdest contains "MMHK", insert only 1sttime into table2, insert the code "L" into the field "code" in table2
3. if 2nddest contains "MMHK", insert only 2ndtime into table2, insert the code "R" into the field "code" in table2
4. if 1stdest and 2nddest has no "MMHK", do not insert anything
table1
transno 1stdest 2nddest 1sttime 2ndtime
===== ===== ====== ===== ======
B1234 ACCY MMHK 1530 0040
C9384 GBCY KOWL 0420 1230
P0923 MMHK LOWL 0730 2120
L0932 MMHK CYLW 1300 1700
E0930 EGLL MMHK 1500 2203
Q9827 MMHK QOWL 0412 1217
Z8393 OLWO LXPS 0914 1423
C0920 SOWL MMHK 1725 0617
table2
transno 1stdest 2nddest time code
===== ====== ====== === ====
B1234 ACCY MMHK 0040 R
P0923 MMHK LOWL 0730 L
L0932 MMHK CYLW 1300 L
E0930 EGLL MMHK 2203 R
Q9827 MMHK QOWL 0412 L
C0920 SOWL MMHK 0617 R
thanks.

Hallo,
first of all , you used wrong column names - they cannot start with number.
create table scott.table1
(transno VARCHAR2(5),
c1stdest VARCHAR2(4),
c2nddest VARCHAR2(4),
c1sttime VARCHAR2(4),
c2ndtime VARCHAR2(4))
insert into scott.table1
(select 'B1234', 'ACCY', 'MMHK', '1530', '0040'
  from dual
  UNION ALL
  select 'C9384', 'GBCY', 'KOWL', '0420', '1230'
  from dual
  UNION ALL
  select 'P9023', 'MMHK', 'LOWL', '0730', '2120'
  from dual
  UNION ALL
  select 'L0932', 'MMHK', 'CYLW', '1300', '1700'
  from dual
  UNION ALL
  select 'E0930', 'EGLL', 'MMHK', '1500', '2203'
  from dual
create table scott.table2
(transno VARCHAR2(5),
c1stdest VARCHAR2(4),
c2nddest VARCHAR2(4),
time VARCHAR2(4),
code VARCHAR2(1))
insert into scott.table2 (transno,c1stdest, c2nddest, time, code)
select transno,c1stdest, c2nddest, CASE WHEN c1stdest = 'MMHK' THEN c1sttime ELSE c2ndtime END,
                                   CASE WHEN c1stdest = 'MMHK' THEN 'L' ELSE 'R' END
from scott.table1
where c1stdest = 'MMHK' or c2nddest = 'MMHK'
select * from scott.table2
TRANSNO      C1stdest  c2nddest   time        code
B1234          ACCY           MMHK          0040           R
P9023          MMHK            LOWL           0730           L
L0932          MMHK          CYLW           1300           L
E0930          EGLL           MMHK          2203           RRegards
Dmytro

Similar Messages

  • Transferring data from one to another table

    I am getting delayed in transffering data from one table to another for the purpose of
    making archieve of a transaction table.
    The number of records in question are about five million and the time taking is
    about 3 to 5 hours in Oracle 10g database in Sun SOLARIS config.
    can any one help me in reducing this time

    >> I am getting delayed in transffering data from one table to another for the purpose of making archieve of a transaction table.
    How you are trying to transferring the data? i.e. What commands you are using for this?
    Regards,
    Sabdar Syed.

  • Convert data from internal table to XML file.

    Hi All,
    I am selecting data from database into one internal table.
    Now I want to convert data from internal table to xml file format and save in to my desktop. Please suggest me how I can achieve my requirement.
    Kindly reply me ASAP.

    Use this FM. SAP_CONVERT_TO_XML_FORMAT
    Check this link too -
    Re: Data Export in XML format
    XML files from ABAP programs

  • Transfer data from one type of table to another

    Can some kind soul put me out of my misery and explain how I can get the data from Table1 to Table2
    I'm really struggling!
    Table1
    MerchID
    MatchesSKU
    1
    BR34
    1
    BD16
    2
    DE11
    3
    HB12
    3
    DX15
    3
    DR19
    Table2
    MerchID
    MatchesSKU1
    MatchesSKU2
    MatchesSKU3
    1
    BR34
    BD16
    2
    DE11
    3
    HB12
    DX15
    DR19

    I've got a page which shows a piece of merchandise in detail. Below that is a section called "you may also like..." and it shows 3 matching items to the main merchandise.
    I currently hold the matching data in a table like Table1 but I've been getting some performance issues and have narrowed it down to the query that gets the 3 matches.
    I was thinking if I place the 3 matching merchID's into the corresponding row of the main merchandise being shown, it saves hitting the database for the 3 matching items?
    Here's the SQL used to find the matching items
              SELECT *
              FROM merchandise
              INNER JOIN matches_with
              ON merchandise.supplier_code = matches_with.matches_with_supplier_code
              WHERE matches_with.merchandise_ID = '#URL.ProductID#'
    I limit the CFQUERY to MAXROWS=3

  • How do I merge data from table1 on server 1 to final table on server 2 with a stored procedure to execute every so many hours.

    How do I merge data from table1 on server 1 to final table on server 2 with a stored procedure to execute every so
    many hours.

    How big is the table on server B? Is that possible to bring the all data into a server A and merge the data locally?
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How do I merge data from table1 on server 1 to final table on server 2 with a stored procedure to execute every 4 hours.

    How do I merge data from table1 on server 1 to final table on server 2 with a stored procedure to execute every so many hours.

    Hello,
    If you had configure server2 as
    linked server on the server1, you can run the following statement inside stored proceduce to copy table data. And then create a job to the run stored proceduce every 4 hours.
    Insert Into Server2.Database2.dbo.Table2
    (Cols)
    Select Cols From Server1.Database1.dbo.Table1
    Or you can use the SQL Server Import and Export Wizard to export the data from server1 to server2, save the SSIS package created by the wizard on the SQL Server, create a job to run the SSIS package. 
    Reference:http://technet.microsoft.com/en-us/library/ms141209.aspx
    Regards,
    Fanny Liu
    Fanny Liu
    TechNet Community Support

  • Ssis - import data from flat file to table (sql server 2012)

    i have create a ssis for importing data from flat file to table in sql server 2012.
    but i got the below error for some column in data flow task.
    error: cannot processed because than one code page (950 and 1252)
    anyone helps~

    Hi,
    The issue occurs because the source flat file uses ANSI/OEM – Tranditional Chinese Big5 encoding. When processing the source file, the flat file connection manager uses code page 950 for the columns. Because SQL Server uses code page to perform conversions
    between non-Unicode data and Unicode data, the data in the code page 950 based input columns cannot be loaded to code page 1252 based destination columns. To resolve the issue, you need to load the data into a SQL Server destination table that includes Unicode
    columns (nchar or nvarchar), and convert the input columns to Unicode columns via Data Conversion or the Advanced Editor for the Flat File Source at the same time.
    Another option that may not be that practical is to create a new database based on the Chinese_Taiwan_Stroke_BIN collation, and load the data to non-Unicode columns directly.
    Reference:
    http://social.technet.microsoft.com/Forums/windows/en-US/f939e3ba-a47e-43b9-88c3-c94bdfb7da58/forum-faq-how-to-fix-the-error-the-column-xx-cannot-be-processed-because-more-than-one-code-page?forum=sqlintegrationservices 
    Regards,
    Mike Yin
    TechNet Community Support

  • How to select data from a PL/SQL table

    Hi,
    I am selecting data from database after doing some screening i want to store it in a PL/SQL table (temporary area) and pass it to oracle reports.
    Is there any way to select the data from a PL/SQL table as a cursor. Or is there any other way of holding the temporary data and then pass it back as a cursor.
    Regards
    Kamal

    A PL/SQL "table" is anything but a table. Whoever came up with this term in PL/SQL to describe what is known as dynamic arrays (the correct programming terminology that existed since the 70's if not earlier and what is used in all other programming languages I'm familiar with)... well, several descriptions come to mind and none of them are complimentary.
    You cannot "select" from a PL/SQL dynamic array as it is not a table within the Oracle context of tables.
    Thus you need to convert (cast) a PL/SQL dynamic array into a temporary Oracle data set/table in order to select from it. This is in general a Bad Idea (tm). Oracle tables and SQL and concurrency controls and all that are especially designed for processing data. PL/SQL arrays is a very simplistic data structure with very limited usage. Why would you want to use that in SQL via a SELECT statement when you can use Oracle tables (or proper temp tables) instead? Besides that, it is also slow to cast a dynamic PL/SQL array into an Oracle SQL data set structure (context switching, copying of memory, etc).
    The proper way to use PL/SQL to generate data sets for use via the SQL engine is pipelined table functions.
    This is not to say that you should never use PL/SQL arrays and casting in SQL.. simply that you need to make sure that this is the correct and scalable way to do it. And that will also always be an exception to the rule when you do.

  • How to convert date from "yyyymmdd" to "MM/DD/YYYY" format

    1. I have one BLDAT field in my internal table.
       its getting updated from input file.
    2. The value in the input file is like yyyymmdd.
       So the internal table field is filled like this
       "YYYYMMDD".
    3. After this,I have to compare this internal table  
       field with BSAD table.
    4. The BLDAT field in BSAD table is in the format of 
       "MM/DD/YYYY".
    5. the BLDAT field is having diff format in internal  table and BSAD table.So I am unable to check this value.
    How to convert it as like the BSAD table format."MM/DD/YYYY" format.
    Thanks in advance!!

    Using the WRITE statement
      data: gd_date(10).  "field to store output date
    * Converts date from 20020901 to 09.01.2002
      write sy-datum to gd_date mm/dd/yyyy.
    OR u can
    CONCATENATE gd_date+4(2) gd_date+6(2) gd_date+0(4)
    into gd_date seperated by '/' .
    Hope this helps.
    Kindly reward points and close the thread for the
    answer which helped u OR get back with queries.

  • Is it possible to show data from two different sql tables?

    Is it possible to show data from two different sql tables? Either to show combined data by using a join on a foreign key or showing a typical master detail view?
    I have one table With data about a house, and another table With URL's to images in the blob. Could these two be combined in the same Gallery?
    Best regards Terje F - Norway

    Hi Terje,
    If you have a unique key, you could use one of the following functions for your scenarios:
    If you only have one image per house, you can use LookUp:
    http://siena.blob.core.windows.net/beta/ProjectSienaBetaFunctionReference.html#_Toc373745501
    If you have multiple images per house, you can use Filter:
    http://siena.blob.core.windows.net/beta/ProjectSienaBetaFunctionReference.html#_Toc373745487
    Thanks
    Robin

  • Select data from Table1 based on Table2

    Hi Guys,
    Can you guide me up on how to select data from Table1 based on Table2?
    I want to fetch data which is not there in table2 in my table1 select query.
    Is that I have to do it with the loops after I select data from both tables or can it be handled directly in my select query?
    Please suggest.
    Regards,
    Kumar.

    hi
    Try This
    In Where condition filedname (Not Equal) < > itab2-fieldname.
    select * from itab1
    into table lt_tab.
    seect * from itab2
    into table lt_tab
    for all entries in lt_tab
    where name < >(Not Equal to)itab2-fieldname.

  • Converting date from DD.MM.YYYY  to  YYYY - MM - DD  format

    Hi All,
    Can you give me a way to convert date from DD.MM.YYYY  to  YYYY - MM - DD  format. Actually frm tables i am getting date in DD.MM.YYYY format.  And i want to print it in YYYY-MM-DD format.
    Please reply.
    Thanks And Regards,
    Mayank Verma
    Moderator message - Please search before asking. Date formatting is one of the most common questions asked - post locked
    Edited by: Rob Burbank on Jul 6, 2009 10:42 AM

    Hi,
    Hey you can make use of offset  and concatenate statement to convert the date.
    regards,
    Ankur Parab

  • I want to convert date from Microsoft Access to Oracle.

    I want to convert date from Microsoft Access to Oracle.
    My Oracel date format is 21-Jul-2004 02:24:09 AM
    I use sqlldr in Oracle 9i Database and I
    write control file
    load data
    infile 'test.txt'
    into table test
    fields terminated by "," optionally enclosed by '"'
    trailing nullcols
    name,
    birthday
    data file 'test.txt' for input
    "dao","21-Jul-2004 02:24:09 AM"
    why did error? ORA-01843: not a valid month
    Thank.

    replace birthday with
    birthday "to_date(:birthday, 'DD-Mon-YYYY HH:MI:SS AM', 'NLS_LANGUAGE=''american''')"Of course, if your monthes are in German, then set the language to german (JUL=JUL but DEZ<>DEC)
    Regards
    Laurent

  • How to insert data from JTable to mysql Table....

    hello everybody
    i need help about how to insert data from JTable to mysql table... i know about how to create Table model...facing problem about how to insert data from JTable to mysql table....any helping link or code ... ill be thankfulll....for giving me solution...

    table1.getValueAt(table1.getSelectedRow(),0)you are getting the value of a selected row... or if you want you can just use a loop..
    for(.....){
    table1.getValueAt(x,y);
    }I think you know INSERT STATEMENT.. here on it just string concat
    sample e.g. (This not insert)
    "delete from accrule " +
                    "where ruleid= " + tblRA.getValueAt(tblRA.getSelectedRow(),0)+
                    " and accountname='"+tblRA.getValueAt(tblRA.getSelectedRow(),1)+"'"

  • Need to convert  Date from calendar to String in the format dd-mom-yyyy

    Need to convert Date from calendar to String in the format dd-mom-yyyy+..
    This is absolutely necessary... any help plz..
    Rgds
    Arwinder

    Look up the SimpleDateFormat class: http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html
    Arwinder wrote:
    This is absolutely necessary... any help plz..For you maybe, not others. Please refrain from trying to urge others to answer your queries. They'll do it at their own pace ( if at all ).
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
    (Yes I know it's on JavaRanch but I think it applies everywhere)
    ----------------------------------------------------------------

Maybe you are looking for

  • Some filters are not available

    All my filters are not available but they used to be. ?

  • ICloud restore confirmation showing email that isn't mine

    So I tried to restore my iCloud backup, entered my info into the phone, then I had to do the confirmation. It says enter the Apple ID for <email> to use for store purchases. Problem is the email isn't mine. Not an old one, just some random email. I s

  • Two problems with a grep solution?

    Hello! I have two problems that I need some help with. I've been searching around for solutions, but are unsure what approach that is the best: A: I need a new (or next) paragraph style after TWO hard line breaks. How do I do this? Do i search for tw

  • Weigh Bridge with SAP

    Hi SAPERS, Please provide me the information about how to connect the vehicle weigh bridge system to SAP system to get automatic net weight should be populates at the time of GR. Is there any interface is required for it. Thanks in Advance, Durga Pra

  • Thousands of photo duplicates

    Help! I am a new Mac/iPhoto user and am swimming in duplicates of photos, due to indiscriminate dowloading of several backup CDs. Trouble is, I have loaded over 3000 photos into library, and am now stuck because I can't get rid of duplicates without