Cleaning up data

I have to clean-up some data in an existing table, so we can move towards a cleaner design:
The data I currently have:
ID____Plan Name_____Effective Date_____End Date
1______Plan A_______ 01/01/2005_______NULL
2______Plan A_______05/02/2005________NULL
3______Plan A_______03/03/2006________NULL
4______Plan B_______01/02/2005________NULL
5______Plan B_______10/15/2005________NULL
6______Plan C_______01/01/2005________NULL
It is safe to assume the Effective end date will be in same incremental order as the ID.
When there is more than one instance of a Plan, I want to set the 'End Date' to 'Effective Date - 1' of the next record (identified by the ID). The End Date of the most recent record should remain NULL.
The result table should look like this:
ID____Plan Name_____Effective Date_____End Date
1______Plan A_______ 01/01/2005_______05/01/2005
2______Plan A_______05/02/2005________03/02/2006
3______Plan A_______03/03/2006________NULL
4______Plan B_______01/02/2005________10/14/2005
5______Plan B_______10/15/2005________NULL
6______Plan C_______01/01/2005________NULL
Anyway to do this?

Take your pick of methods. The first one requires that the next id = the previous id + 1, but the second one does not.
scott@ORA92> SELECT * FROM your_table
  2  /
        ID PLAN_NAME EFFECTIVE_DATE END_DATE
         1 Plan A    01/01/2005
         2 Plan A    05/02/2005
         3 Plan A    03/03/2006
         4 Plan B    01/02/2005
         5 Plan B    10/15/2005
         6 Plan C    01/01/2005
6 rows selected.
scott@ORA92> UPDATE your_table t
  2  SET    end_date =
  3           (SELECT effective_date - 1
  4            FROM   your_table
  5            WHERE  id = t.id + 1
  6            AND    plan_name = t.plan_name)
  7  /
6 rows updated.
scott@ORA92> SELECT * FROM your_table
  2  /
        ID PLAN_NAME EFFECTIVE_DATE END_DATE
         1 Plan A    01/01/2005     05/01/2005
         2 Plan A    05/02/2005     03/02/2006
         3 Plan A    03/03/2006
         4 Plan B    01/02/2005     10/14/2005
         5 Plan B    10/15/2005
         6 Plan C    01/01/2005
6 rows selected.
scott@ORA92> ROLLBACK
  2  /
Rollback complete.
scott@ORA92> UPDATE your_table t
  2  SET    end_date =
  3           (SELECT lead_date
  4            FROM   (SELECT id,
  5                     LEAD (effective_date) OVER
  6                       (PARTITION BY plan_name
  7                        ORDER BY id) - 1 AS lead_date
  8                 FROM   your_table)
  9            WHERE  id = t.id)
10  /
6 rows updated.
scott@ORA92> SELECT * FROM your_table
  2  /
        ID PLAN_NAME EFFECTIVE_DATE END_DATE
         1 Plan A    01/01/2005     05/01/2005
         2 Plan A    05/02/2005     03/02/2006
         3 Plan A    03/03/2006
         4 Plan B    01/02/2005     10/14/2005
         5 Plan B    10/15/2005
         6 Plan C    01/01/2005
6 rows selected.
scott@ORA92>

Similar Messages

  • How can I clean all data in a database but keep all datafile still same nam

    hi,
    How can I get a easy way to clean all data in a database but keep all datafiles still same name and location just like a new created database?
    dbca has two choice: create templet without datafile or with all datafiles but not empty datafiles.
    thanks

    What version is your database? DBCA in 10gR2 allows you to create a template from an existing database using only the structure. From DBCA
    From an existing database (structure only)
    The template will contain structural information about the source database including database options, tablespaces, datafiles, and initialization parameters specified in the source database. User defined schemas and thier data will not be part of the created template.

  • Is there a way to clean up data without restore and backup?

    I noticed recently that too much data is being silently stored on my iPad possibly be apps and caches.
    Isn't iOS supposed to clean up data as it needs free storage?
    most recently, according to usage in settings > general, I had 1.8 GB of free space. I wanted to install an app that is 2GB in size. iOS told me there was not enough free space. I could not find what used so much data, and frankly this time the list of apps in settings > general > usage proved to be pointless. Adding the numbers together of how much space the apps were using up was nowhere near enough to leave me with only 1.8 GB of free space.
    I did a backup, then restored my iPad. After that, I restored the backup with all apps and data I had before. Now I have 7.2 GB free space. 5.4 GB of temporary and junk files, with no way of erasing them, is quite frustrating.
    Anyone knows a solution or shall I just restore my iPad pretty much every 2-3 weeks? (Yes, the last 5 or 6 restores I have performed were solely for freeing up storage space that mysteriously keep being filled up.)
    Additionally, how do I find out which apps use up so much space when settings > general > usage doesn't tell me anything? Only how much space the app itself needs and how much permanent (user generated) data is being stored. Such as pictures, save game files, and so on, but nothing about cache sizes temporary data.
    PS: if the above was asked and answered before, please accept my apologies and could you link me the topic it has been resolved in?

    Hi! And thanks for your reply!
    It sounds sensible. Since the last restore which was just over a day at the time of me writing this reply, there is over 1GB of data unaccounted for. Note that I have not installed new apps, nor DLCs within games. The two I have been using heavily are Netflix and Youtube, both of which should automatically erase temporary data. Or so they claim.
    However, there was a period when I had my iPad on charger overnight. When I woke up, just out of curiosity I checked the usage statistics and I found my free space was about 200 MB less than when I checked immediately before goong to bed. So the iPad was not used at all and somehow I lost 200MB.
    I did try a software for Windows called Phone Clean, but that didn't help. Before the restore, I ran a deep scan, and it only cleaned up about 500MB of data even though there was nearly 5GB unaccounted for. I performed the restore, and that was when I thought this is beyond me, and posted this topic.
    I have also noticed that when I watch a movie with the Videos app by streaming from iTunes instead of downloading, after watching it, the storage will not get freed up. The movie is still there (as confirmed by trying to actually download another that was larger than the current free space, then the previous movie file was indeed deleted by iOS automatically) but it does not show up in usage > videos. According to iOS the Videos.app has no data within.
    I'll try a full reset soon and see how it goes. Obviously it will take some time to test it, but I'll let you know of any results. Luckily, I don't have many apps that don't use iCloud storage so their data should be there despite dropping the backup, and installing them clean should be easy using iTunes on a PC.
    If that doesn't help, I go one step further and download the apps one by one.
    Well, there is plan.
    To be honest, it would really be helpful if we could see individual app containers as that way we can easily find out which app is being naughty.
    Any way, thanks for the tip! Give me a couple of days and I'll let you know how it went.

  • DPM 2012 R2 - Failed to clean up data

    Hi,
    I'm hoping someone might be able to help me.
    I've recently been getting an error on one of our backup jobs, I've tried searching around for solutions but no-one seems to have had the exact same issue that I'm experiencing.
    The backup job is a shadow copy file backup of a complete volume.
    It's been working for the past few weeks but I'm now getting the error below when I try to run a consistency check. 
    People have reported issues similar which suggest executing the pruneshadowcopiesdpm2010.ps1 which I've tried but this seems to make no difference.
    The protection group is short term disk protection with a retention period of 14 days with file recovery points created at 11am, 1.30pm, 3.30pm and 8pm.  The job is currently reporting 32 recovery points which leads me to believe it shouldn't need to
    clean up any yet anyway.
    Any suggestions would be very much appreciated.
    Type: Consistency check
    Status: Failed
    Description: DPM failed to clean up data of old incremental backups on the replica for Volume D:\ on nas01.nwhs.local. Synchronization will fail until the replica cleanup succeeds. (ID 30134 Details: Cannot create a file when that file already exists (0x800700B7))
     More information
    End time: 29/04/2014 18:48:03
    Start time: 29/04/2014 18:48:02
    Time elapsed: 00:00:01
    Data transferred: 0 MB
    Cluster node -
    Source details: D:\
    Protection group: User Data
    Items scanned: 0
    Items fixed: 0

    RIS,
    The access denied can come if there is already a lock on the file( like Antivirus). 
    Can you let me know what version of DPM2012R2?   if you goto about DPM you it will give you exact version 4.x.xxxx.x.  You stated you had AV exclusions set
    "We do run Sophos Antivirus but it does have exceptions set and the volumes that are being protected do not store any Sophos related data."
    I want to ensure all are set from -
    http://technet.microsoft.com/en-us/library/hh757911.aspx - if you can test disabling AV that may help.
    Can you check the event logs on DPM server and PS during the failure to see if there is anything else running that may lock the files?
    There may also be a "failedfiles.dat" that may due to unsupported files see link below for assistance troubleshooting that -
    http://social.technet.microsoft.com/Forums/en-US/f7de60cd-841f-4d22-862e-aaf3723717c7/dpm-could-not-log-files-that-were-skipped-during-backup-to-volumexxxxxfailedfilesdat-id?forum=dataprotectionmanager
    How to read failedfiles.dat if there is one -
    http://social.technet.microsoft.com/Forums/en-US/dataprotectionmanager/thread/27c48816-dabb-41a0-b800-6e1ac2fc1ed5
    Also what is the OS version of the DPM server?  Are you doing any dedupe\ODX\Thin provisioning on the protected server? 
    Ultimately we may need a ticket to determine what is locking out the file during the failure but please let me know the answers to the above and I will see if that helps.  Thanks
    Regards, A.Nadar, This posting is provided "AS IS" with no warranties, and confers no rights.

  • How to clean session data

    how do you clean session data after access 2-3 webapps in 3 diff JVMs aftre logout?

    how do you clean session data after access 2-3 webapps in 3 diff JVMs aftre logout?

  • Bought  a used ipod  4 th and it came with a restrictions passcode. What can i do  to either reset or reset and wipe clean all data?

    Bought  a used ipod  4 th and it came with a restrictions passcode. What can i do  to either reset or reset and wipe clean all data?

    Forgotten RESTRICTIONS Passcode
    - Place the iOS device in Recovery Mode and restore via iTunes. For how to restore: iTunes: Restoring iOS software
    Then
    - Restore to factory settings/new iPod

  • Clean up data in AP ???

    Hi Experts
    Please guide me in figuring out How to clean up the data in Configuration system in terms of  Accounts Payable Invoicing and Payment Processing standpoint?
    Before starting the testing in Config system we have to do the cleaning.
    Can anyone please explain me how to do the above process with set of steps or t codes?
    Thanks in Advance
    Meenakshi.N

    You may want to try out the spro menu path under Financial accounting> financial accounting global settings>Delete transaction data. This runs the program SAPF020. Read the documentation, This may be of some help.

  • Help needed in cleaning raw data with odd delimiters in it

    I am trying to write a sp, which adjust the number of columns based on the IN Parameter for the raw file.
    Raw (Id Int,RawData varchar2(5000))
    RawData has actual data with delimiter, this column has all the raw file imported as is.
    e.g. data in RawData Column
    A|B|C|D|E|F
    X|B|C|D|E
    Z
    P|ABC|ZPD|BITX|E|ETC
    Here above you can see the max number of delimiter are 5 for a 6 column table, however for some records there are less delimiter, here comes the problem
    For such records I want to add the extra delimter and take values for missing column as NULL or best would be''
    plz help me in writing Generic SP to clean this.
    We can pass the source & target table name and column names as a parameter, and create a clean table dynamically by name CleanedRaw etc.
    here the file is | delimited, actually It can have any single char delimiter or space or tab also. I am ok if we need to pass the delimiter also as a parameter to this sp

    I mean padd extra delimiters to make up to the max of 6 for this file, it can vary for other file
    e.g
    A|B|C
    x
    would be some thing like
    A|B|C
    x||
    such that target cleaned table will have values as below
    Col1 Col2 Col3
    A    B    C
    X       Edited by: NeilCSE on Jul 28, 2012 12:54 PM

  • UNIX sed commands to clean up data before loading into BI

    Hi all,
    we are trying to load the data into BI from text files.. This data needs to be cleaned before it can be loaded into BI and this has to be done using UNIX sed commands!!
    We basically need to do a data cleansing act, like removing unwanted characters (tab values and newline values as part of the characteristic values). How can it be done using unix sed commands??
    your help is very much appreciated.
    Regards

    Hi all,
    we are trying to load the data into BI from text files.. This data needs to be cleaned before it can be loaded into BI and this has to be done using UNIX sed commands!!
    We basically need to do a data cleansing act, like removing unwanted characters (tab values and newline values as part of the characteristic values). How can it be done using unix sed commands??
    your help is very much appreciated.
    Regards

  • Command the execute sql query and does not clean up data in Table

    Hi Team
    I have an SP, which writes source and target data to Temp Tables and runs except query to get mismatch details
    I am using Exec command to execute source query that writes data to Temp Table, once I execute query using Exec, data is written and immediately #temp table is cleaned, now I cannot use #temp table for comparition.
    Is there any way to execute sql query in SP without using EXEC and will hold the data in temp table.

    You need to create temp table before EXEC statement and rewrite your dynamic query also as below
    declare @source_Sql nvarchar(1000)
    ,@target_Sql nvarchar(1000)
    create table #TempTable1 (name nvarchar(10))
    create table #TempTable2 (name nvarchar(10))
    set @source_Sql = 'INSERT INTO #TempTable1 SELECT [Name] from Employee'
    set @target_Sql = 'INSERT INTO #TempTable2 SELECT [Name] from Employee2'
    EXEC (@source_Sql)   
    EXEC (@target_Sql)             
    select * from #TempTable1 
     Except 
    select * from #TempTable2

  • Problem when cleaning HTML data in coldfusion

    Hi,
    I have below piece of CF code to clean&convert HTML data into a well formatted one.
    <cffunction name="cleanHTML" returntype="string">
         <cfargument name="sHTML" type="string" required="yes">
           <cfset sHTML = reReplace(sHTML, "\r\n(\S?)<br>\s*(<(u|o)l>)", "\1", "all")>
           <cfset sHTML = reReplace(sHTML, "</?(p)>(\s+| +)*(<br>(\s+| +)*)+$", "", "all")>
         <cfreturn sHTML>
    </cffunction>
    <cfquery name="getDetailsOfReport" datasource="datasource_name" >
    select details from reports where report_id = 1326065
    </cfquery>
    <cfoutput>#cleanHTML(getReport.details)#</cfoutput>
    Above code is working fine when getDetailsOfReport query is returning small amount of data, however fails when query returns large data.
    Note:
    Details column of REPORTS table is a clob field which contains html data.
    Can anybody assist me solving this issue?
    (OR)
    Please let me know the right procedure to clean HTML if I am on the wrong way.
    Thanks in advance,
    Best Regards,
    Manoz.

    Clean & Convert means,
    1) Remove new lines from html
    2) Remove breaks before lists eg <br><ol>
    3) Get rid of paragraph tags
    4) Get rid of trailing line breaks (including white space and forces spaces  
    The expected input is some HTML content
    eg:
    <ul>
        <li><span style="font-size: 7.5pt; font-family: Verdana; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-bidi-font-family: 'Times New Roman'">Tool measurement assessment in lab achieved.</span></li>
        <li><span style="font-size: 7.5pt; font-family: Verdana; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-bidi-font-family: 'Times New Roman'"><span style="font-size: 7.5pt; font-family: Verdana; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-bidi-font-family: 'Times New Roman'">1<sup>st</sup> coil tubing job.</span></span></li>
    </ul>
    And the expected output is also HTML content (But after applied above 4 operations to the given input).

  • Best way to clean all data n8

    hello, can anyone please tell me whats d best way to clean out all data - phone numbers, photos, videos maps, apps all from d from my n8, i have backed up necessory info usin ovi sync, i just want a clean fresh start with d phone is too full
    Solved!
    Go to Solution.

    Enter *#7370# followed by the security code which is 12345 by default. You must have a SIM inserted for this to work I believe (been a while).
    This will erase all data and restore settings to factory defaults.
    Click on the blue Star Icon below if my advice has helped you or press the 'Accept As Solution' link if I solved your problem..

  • Cleaning of data in system

    Hi Apo expert,
    In our organization we have detached one unit. Same was working as a location (having different products), now for cleaning purpose we need to delete all the data related with that.
    How to go-ahead to do this !

    Hi
    it is not a plain thing to delete a product master/location product in a production system.You have to carry out the following steps:
    1.
    a) Remove product from integration model
    b) Delete all orders for this product-location which still exist in the APO system by running the reports /SAPAPO/RLCDELETE or /SAPAPO/DELETE_PP_ORDER (this report is not recommanded to be used in product system!!) or transactions /SAPAPO/RRP4 or /SAPAPO/RRP4.
    c) Use transaction /sapapo/ccr to delete all objects in APO that are integrated with R/3. The /sapapo/ccr will show the orders as 'Not in an active integration model' and offers to delete the orders in APO
    d) Delete the product from ATP tables by running the report /SAPAPO/SDORDER_DEL with the selection according to the product being deleted. (Orders from DB & live cache)
    e) Delete all related product substitution and location product substitution using the transaction /SAPAPO/RBA04;
    f) Delete the product from all PPMs through the transaction /SAPAPO/SCC05;
    g) Remove the product from external procurement using the transaction /SAPAPO/PWBSRC2;
    h) Remove the product from transportation lanes through the transaction /SAPAPO/SCC_TL1 or /SAPAPO/SCE; Note: If the lane was created with option 'All products', you should not care about this condition.
    i) Remove the product from quota arrangement through the transaction /SAPAP/SCC_TQ1;
    j) Remove references from the product master or the location product master using the transaction /SAPAPO/MAT1, tab 'Classification';
    k) Remove the planning package from the location product master using the transaction /SAPAPO/MAT1, tab 'PP/DS';
    l) Remove the product from RTO;
    m) Remove the product from product split.
    Product-specific transportation lanes, for which you have set the deletion flag, can be deleted using report /SAPAPO/TR_TRPROD_DELETE
    2. Mark deletion flag
    a) In transaction /SAPAPO/MAT1, select the product (and location in case of location product);
    b) In the menu bar, choose 'Product' and go to 'Mark for deletion' (Shift+F6);
    c) In the popup 'Set deletion Flag' set a flag in the appropriate field: Leave the field 'Product' empty unless you want to delete the product master, i.e. in case a location product must be deleted, the flag has to be set on location only;
    d) The deletion can be executed directly or be scheduled for another time.
    I hope this will help you,
    Thanks
    Amol

  • Manually clean WSUS Data Base

    SBS2008 SP2
    Current WSUS
    I forgot to do a regular cleanup of the data base. It is now 20 GB in size. When I do a options - cleanup and only check Unused and update revision, it runs for several hours and then gets a Database error. I Reset Server Node and WSUS comes back. I noticed
    that the blue fuel gauge bar did start but only minimally.
    I did run unneeded, expired and superseded one at a time and then went to completion quickly.
     Is there a manual method to purged the data base?
    THX
    John Lenz

    Hi Clarence
    "Clarence Zhang" schrieb im Newsbeitrag news:[email protected]...
    Running the cleanup wizard is the only way to shrink the DB.If the DB
    is extremely big,it may lead to running serveral hrs to clean up the DB.
    The cleanup wizard (at least for WSUS 3.0 where I tried) doesn't shrink the DB at all. The space may be free and be reused after but the db flies aren't shrinked (which actually makes sense as SQL Server else has to make it larger again later). First step
    sure is to run the wizard to get rid of obsolete updates filling the database and file system.
    If you after this run still have real need on wasted storage you can do following:
    - Ensure Windows Internal Database Service is started
    - Start the Management Studio of SQL Server 2008 R2. Important: You have to start it with "Run as Administrator", else you won't get the required permissions.
    - Link to the Windows Internal Database server using the pipe as server address:
    \\.\pipe\MSSQL$MICROSOFT##SSEE\sql\query
    - Now you should be connected to the WSUS3 Database server and see in the Branch Databases the Database SUSDB.
    - Rightclick on it and select the Task to shrink either the database or the files what ever you prefer.
    BTW: For me this reduced the size of the database files (data and log file) from 8.5GBytes to 3.5GBytes.
    Now the database should be shrunk to a reasonable size and the unrequired space should have been freed up on the disk.
    But again - WSUS will have to expand the database file when running and the database may grow to the seen size quickly again.
    HTH
    Henry

  • Lion: Spinning Ball using Mail - Attempting to "clean" all data

    I've read dozens of threads on the Spinning Ball Syndrome with Lion and Mail. I've tried all of the suggestions and still no luck.
    My case is unique, and should be simple to solve - because I never set up any mail accounts and am willing to delete ALL mail files.
    Sometimes I get the spinning ball and have to force quit.
    When I start the Mail app, sometimes it doesn't even appear as an app starting up, but I can use command-tab to switch apps and find it.
    I would appreciate anyone's help:
    Can I REMOVE ALL mail data files and start "clean"?
    Background:
    Used a Mac Mini for 3+4 years as a music media station. NEVER set up any mail accounts on the machine.
    Upgraded through a few OS generations up to Lion.
    Bought a new Mac Mini about a week ago.
    Before migrating data to the new machine, I updated all software, verified and repaired disk permissions, and ran fsck -yf in single user mode on the source.
    Then I migrated the data to the new machine using migration assistant, including user settings.
    Updated all software.
    I've verified permissions, repaired them. Verified the hard disk. No errors. And I've removed files that were mentioned in related threads.
    - Removed
    /Library/Preferences/
    com.apple.mail.plist
    com.apple.mail.plist.lockfile 
    No change
    - Went to
    /Library/Mail/V2 (that was the only folder)
    Clicked on Maildata and removed everything except for:
    accountsplist
    messageruleplist
    No change
    Please see the attached screen shot of my /Library/Mail/V2 directory. Everything looks stripped and recent.
    Is there anything else I can get rid of?
    Any other suggestions appreciated.
    Hardware: New Mac Mini (it wasn't preloaded with Mountain Lion)
    Lion v 10.7.4
    2.5 GHz Intel Core i5
    Still only 4GB RAM (Haven't had a chance yet to install new RAM)
    Jim

    Please repost on the correct forum, this is an iMac forum. There are forums specifically for Mac Mini users, however the answers will probably still be the same.

Maybe you are looking for

  • About getting the values from a FM

    Hi experts,                  I have used the function module 'HR_READ_INFOTYPE' to get all the field values of the infotype 0008 (Basic Pay). I have given the infty as 0008 in exporting and infty_tab as p0008 in tables. But it shows a run time error

  • Unable to generate PostScript reports

    We need to generate report output in PostScript format using, http://hostname:port/DEV60CGI.EXE If the following option is given (along with other report parameters), DESTYPE FILE/CACHE DESFORMAT EPS the report server throws up an error. "Invalid nam

  • Connecting Clearwire modem to WRT54G ver1.1 router

    Am trying to convert from a DSL line to CLEAR.  I cannot get the clear modem to work with the Linksys router even after putting latest firmware on the router.  CLEAR tech said all that is needed was to set the router to DHCP instead of PPoE.  I can c

  • 1Z0-051 exercises for preparing the exam

    Hello, I'm preparing for the 1Z0-051 exam and It could be useful for me some link o similar with exercises about SQL. Thanks in advance. Regards.

  • Benifits Participation Overview - No valid target content area found

    HI I am getting following error when I click on "Status" column in "Benefits Participation Overview" screen. Please help. Thanks