Change "Date" From a Column in Table A, to New Column in Table B:

I'm trying to pull a Date from TABLE_A, and change the year to a current date, and popluate this into a new table. I also want to pull the PK of TABLE_A over, so that I can create a link back to the master record.
In my example I'm useing SYSDATE for my current date. Once I get the script working, I want to pull the Calander_Date from my "Current Calendar" in APEX.
1. INSERT INTO TABLE_B (NAME_ID,Date,New_Date VALUES (
2. NAME_ID , (This is a Column FROM TABLE_A),
3. DATE, (This is also a Colum From TABLE_A)
4. TO_CHAR(DATE,'DD')||'-'||
5. TO_CHAR(DATE,'MON')||'-'||
6. TO_CHAR(SYSDATE,'YY') )
7. FROM TABLE_A
8 WHERE TO_CHAR(DATE,'MON') = TO_CHAR(SYSDATE,'MON');
Needless to say, this doesn't work!!! I'm very new to SQL and APEX. I've also tried embedding SELECT STATEMENTS, as shown below, but still now dice (Trying to figure out out to calculate the TO_CHAR FROM DUAL and from TABLE_A for the "DATE" Column)
1. INSERT INTO TABLE_B (NAME_ID,Date,New_Date VALUES (
2. SELECT NAME_ID FROM TABLE_A,
3. ELECT DATE FROM TABLE_A,
4. SELECT TO_CHAR(DATE,'DD')||'-'||
5. SELECT TO_CHAR(DATE,'MON')||'-'||
6. SELECT TO_CHAR(SYSDATE,'YY') ) FROM
7. FROM NAMES
8 WHERE TO_CHAR(DATE,'MON') = TO_CHAR(SYSDATE,'MON');
Depending on the modifications I make I usually get the following two errors:
ORA-0933: SQL Command not properly ended (in the first example)
ORA-00936: Missing Expression (in the second example).
Appreciate any thoughts you all might have!!!
LEONHARK

So here's a question: are the different pieces of the day stored in the same column in Table A, or different columns? If they are the same, you can simplify a lot of your data copy procedure to:
  insert into TABLE_B (NAME_ID, SOME_DATE, NEW_DATE)
   values (select KEY_ID, to_date(ORIG_DATE,'DD-MM-YYYY') from TABLE_A
  where to_date(ORIG_DATE,'MM') = TO_DATE(SYSDATE,'MM'));If the dates are stored in individual fields in Table_A, use something like:
  insert into TABLE_B (NAME_ID, SOME_DATE, NEW_DATE)
   values (select KEY_ID, to_date(ORIG_DAY || '-' || ORG_MONTH || '-' || ORIG_YEAR,'DD-MM-YYYY') from TABLE_A
  where to_date(ORIG_DATE,'MM') = TO_DATE(SYSDATE,'MM'));An alternate for your where clause that uses a range of dates instead of a specific month is
  where to_date(ORIG_DATE,'DD-MM-YYYY') between TO_DATE('01-01-2007','MM-DD-YYYY') and TO_DATE('12-31-2007','MM-DD-YYYY');A couple of advantages: a date comparison is much faster than a string comparison and more accurate to what you want. Convert the strings to dates rather than the dates to strings. In my opinion, dealing with dates can be one of the biggest headaches for those learning SQL. There are a lot of good helps out there, but you will want to familiarize yourself with the TO_DATE() and TO_CHAR() functions, because you will use them a lot!
Also, store dates as DATE datatypes! Do NOT store them as text! You will save yourself a lot of headaches and your queries will run much faster if you use DATE datatypes.

Similar Messages

  • Copy the data from first line while dynamically adding a new line in table

    Hi,
    1. There is a table
    2. An add button adds a new line to the table using 'AddInstance'
    3. A record is entered in the first line
    4. When the add button is clicked it adds a new line and along with it copies the data entered in the first line
    My question is how to copy the data from the first line and show it in the new line added. This is required so that user can use most of the common values in the first line.
    Thanks,
    Nikhil

    You can use the following Java Script in the Click event of the button.
    // Get the number of rows in the table
    var nrows = xfa.resolveNodes("page.table.DATA[*]").length;
    // Add a new instance(row) to the table
    page.table.addInstance.instanceManager(1);
    xfa.form.recalculate(1);
    // Copy the values from the first line to the newly created row
    page.table.DATA\[ nrows \].field1.rawValue = page.table.DATA\[ 0 \].field1.rawValue;
    ..........field2
    ..........field3
    Thanks,
    Chandra Indukuri

  • Approaches to transfer changed data from a table to another table

    Hello expert,
    will you please show me all approaches to automatically detect and transfer changed data from a table to another table ? I don't need detail information, but a little comment for those approaches are more welcome.
    Many Thanks,
    Edited by: 843178 on 19-Dec-2011 2:04 PM

    You will want to review information on replication and similar methods
    In a nutshell:
    Replication allowed data to exist at more than one site and take the Master / original table data and clone it at a different site
    As tranporting all of the table data to a remote / clone site got more and more expensive we developed a method
    to identify just the 'diffs' and only send those from the master to the clone which needed only the diffs to become a clone of the master table
    This has many methods and options, but looking under key words such as
    - distributed transations
    - materialized views
    - replication
    ... are a few categories that will get you started

  • How can I take data from multiple pages documents and put them into a numbers table?

    I produce invoices in pages, with dates, invoice numbers, references and amounts due. I want to take all this data from multiple documents and transfeer it to a single numbers table. Is this possible and if so, how do I do it. I know I can do it the other way round with mail merge but I can't figure out how to do it this way round?
    Thanks,
    Keith

    The data is spread throughout a pages document in specific areas here's a copy of an invoice for you to have a look at.

  • Can not change date from 2011 to 2012 in Elements 9 photoshop

    can not change dates from 2011 to 2012 in Elements 9 photoshop

    Thanks for the help. That was exactly  the fix I needed. With the expense of the photoshop software you'd think the company would fix stuff like this via updates. Merry Christmas.

  • When transferring data from an old hard drive to a new one, is there a way to keep alias files and folders in tact?

    My mac and I rely HEAVILY on the use of alias files and folders. The simple version of my question is: When transferring data from an old hard drive to a new one, is there a way to keep alias files and folders in tact?  These are not symlinks or symbolic links, they're all alias files and folders. 
    Is there any software out there that might help me with a solution?  Are there any tricks or tips you can give me to try?

    Use either Setup Assistant at first start, or Migration Assistant on subsequent occasions and all will be transferred intact. Given your wording I presume you are Unix savvy and will appreciate the problems that duplicate userids would cause, so of you use MA for the migration, make sure the target Mac has no userid equal to that on the source and you will be fine.
    SA does not have these issues since it runs before any user account is created, so it can simply copy over everything. But MA runs after the fact and only solves the issue partially by changing the UID in the user directory, leading to permission problems.

  • 've Password job a year ago to Mobil iPhone 4, and now lost and I can not wipe data from the device or transferred to the new device .. What do I do?

    've Password job a year ago to Mobil iPhone 4, and now lost and I can not wipe data from the device or transferred to the new device .. What do I do?

    iPhones require a SIM for activation.
    Put the device in DFU mode (google it) and restore via iTunes.

  • How can I restore the game data from an old ipod touch to a new one?

    How can I restore the game data from an old ipod touch to a new one?

    Restore it from the backup of the old ipod.

  • How do I transfer all my data from my Time Capsule 2TB to my new Time Capsule 3TB?

    How do I transfer all my data from my Time Capsule 2TB to my new Time Capsule 3TB?

    Click here and follow the instructions to move a Time Machine backup, and just drag-copy everything else.
    (113074)

  • How do I transfer all my data from my original iPad 1 to my new iPad Air?

    How do I transfer all my data from my original iPad 1 to my new iPad Air?

    Do a full sync and backup of your one. I use iTunes for all my backing up. Then unplug the one and plug in the Air. Go through the setup process and when you have the choice to 'set up as new or restore from backup' chooose the the restore and your air will be a near clone of your One. You will need to reset up wifi and website passwords, but the data should be there.
    Once you are sure the Air has all you need on it, you can go into the settings and 'erase all content and settings' which puts your One back to the 'out of box' state to you can sell it if you want.

  • How do I transfer all my data from my old windows laptop to my new MacBook

    How do I transfer all my data from my old windows laptop to my new MacBook

    Two knowledge base articles that may help are http://support.apple.com/kb/PH11393 and http://support.apple.com/kb/HT1408

  • I had an iPod touch, but it was stolen or lost. Now that I have a new one with a new Apple ID, is there someway I can access and download all my old photos and data from my old Apple ID to my new device? I still remember my old Apple ID and password.

    I had an iPod touch, but it was stolen or lost. Now that I have a new one with a new Apple ID, is there someway I can access and download all my old photos and data from my old Apple ID to my new device? I still remember my old Apple ID and password.

    Restopre from backup
    To restore from backup see:
    iOS: How to back up     
    If you restore from iCloud backup the apps will be automatically downloaded. If you restore from iTunes backup the apps and music have to be in the iTunes library since synced media like apps and music are not included in the backup of the iOS device that iTunes makes.
    You can redownload most iTunes purchases by:
    Downloading past purchases from the App Store, iBookstore, and iTunes Store        
    Also,
    - If you used PhotoStream then try getting them from your PhotoStream. See that topic of:
    iOS: Importing personal photos and videos from iOS devices to your computer

  • HT3224 What cable can I use to transfer data from a 2008 MacBook Pro to a new MacBook Pro with thunderbolt?

    What cable can I use to transfer data from a 2008 MacBook Pro to a new MacBook Pro with thunderbolt?

    You should also ask this in the MacBook Pro forum. This is the forum for the 13” white and black plastic MacBooks that were discontinued in 2010. You should also post this question there to increase your chances of getting an answer.
    https://discussions.apple.com/community/notebooks/macbook_pro

  • HT1296 I bought my wife a new Ipad 3. How do I transfer her data from the old Ipad 1 to the new one?

    I bought my wife a new Ipad 3. How do I transfer her data from the old Ipad 1 to the new one?

    Sync the old one, and get a full back up stored.  Make sure you transfer your purchases to I tunes, and make sure you upload any photos taken on the pad, or imported thru the cck.
    Then plug the new pad in, and set it up from the backup of the old one.  In theory, all the stuff that was in the back up will migrate to the new pad.  If apps, music or books get lost, you can redownload them for free, using the same appLe id.  
    If you are selling or gifting the old one,   When you are done and happy with the new set up,  go to setting, general, reset, reset all content and data.  This will place the pad in factory new condition.   Lastly, if it is a 3 g pad, especially if it a Verizon pad, make sure to cancel the plan

  • How do I transfer back up data from my old time capsule to my new one easily.

    How do I transfer back up data from my old time capsule to my new one easily.

    Before you do this, do you really need all of the old backups that go back many weeks and months?  Most us only ever need to go back a week or two to pick up a file that was accidentally deleted, but that's about it.
    Sure, It is tough to think about deleting all the old backups, so a suggestion would be to keep the old Time Capsule around for a month or two....just in case....but start new backups on the new Time Capsule.  Once you have a month or two of backup history on the new Time Capsule, then you might decide to erase the old Time Capsule and sell it....or just keep it around as a spare hard drive.
    I've tranferred backups a few times in the past, and used up a lot of space on the "new" Time Capsule to do it, and have found that it is far more trouble than it is worth.
    But, you may disagree.

Maybe you are looking for