Update once only most current record that meets conditions

Want to only allow the most current date with the stateID of 1 to update once and not update after the intial update when running sql code over again. 
changeTypeID containerID    stateID dateEntered                               note
UPDATE          900172-0800  5       2014-09-23 04:38:29.313            Pallet #71809
UPDATE          900172-0800  1       2014-11-20 09:17:51.017 
UPDATE          900172-0800  10      2014-11-24 15:03:32.177   900172-0800->Destroyed
UPDATE          900172-0800  10      2014-11-24 15:04:00.777   900172-0800->Destroyed
UPDATE          900172-0800  10      2014-11-24 15:05:44.763   900172-0800->Destroyed
SELECT containerID
INTO #Temp
      ContainerHistory
      WHERE dateEntered >= DATEADD(DAY, DATEDIFF(DAY, 0, CURRENT_TIMESTAMP) -1, 0)
        AND dateEntered < DATEADD(DAY, DATEDIFF(DAY, 0, CURRENT_TIMESTAMP), 0)
        AND stateID = 1 ORDER BY dateEntered DESC ????
UPDATE ContainerStates
  SET stateID = 10,
   dateEntered = getdate(),
   note = containerID + '->Destroyed'
  WHERE containerID IN (
   SELECT barCode AS containerID FROM #Temp WHERE containerExpired = 1

>> Want to only allow the most current date with the state_id of 1 to update once and not update after the initial update when running SQL code over again. <<
Please follow basic Netiquette and post the DDL we need to answer this. Do you know how to follow industry and ANSI/ISO standards? You should follow ISO-11179 rules for naming data elements. You hjave noi idea what that means.  Avoid dialect in favor of
ANSI/ISO Standard SQL. 
There is no such attribute as a “change_type_id” in RDBMS. You can have a “<something>_id” “<something>_type” but not a weird mix of attribute proprieties. Likewise, “state_id” makes no sense. If you meant a status, then you need two dates to show
when that state of being applied to the entity. 
To track the history of, say, Foobars we need to see time as a continuum and model it as (begin_date, end_date) pairs that define when a foobar had a particular value. Here is the skeleton. 
CREATE TABLE Foobar_History 
(foo_id CHAR(9) NOT NULL, 
 start_date DATE NOT NULL, 
 end_date DATE, --null means current 
 CHECK (start_date <= end_date),
 foo_status INTEGER NOT NULL, 
 PRIMARY KEY (foo_id, start_date)); 
When the end_date is NULL, that state of being is still current. You use a simple query for the status on any particular date;
SELECT * 
  FROM Foobar
 WHERE @in_cal_date
     BETWEEN start_date
      AND COALESCE (end_date, CURRENT_TIMESTAMP);
There are more tricks in the DDL to prevent gaps, etc
CREATE TABLE Events
(event_id CHAR(10) NOT NULL,
 previous_event_end_date DATE NOT NULL  
 CONSTRAINT Chained_Dates  
  REFERENCES Events (event_end_date), 
 event_start_date DATE NOT NULL, 
 event_end_date DATE UNIQUE, -- null means event in progress
  PRIMARY KEY (event_id, event_start_date), 
 CONSTRAINT Event_Order_Valid 
  CHECK (event_start_date <= event_end_date), 
 CONSTRAINT Chained_Dates 
  CHECK (DATEADD(DAY, 1, previous_event_end_date) = event_start_date)
-- CHECK (previous_event_end_date + INTERVAL '01' DAYS) = event_start_date)
-- disable the Chained_Dates constraint
ALTER TABLE Events NOCHECK CONSTRAINT Chained_Dates;
GO
-- insert a starter row
INSERT INTO Events(event_id, previous_event_end_date, event_start_date, event_end_date)
VALUES ('Foo Fest', '2010-01-01', '2010-01-02', '2010-01-05');
GO
-- enable the constraint in the table
ALTER TABLE Events CHECK CONSTRAINT Chained_Dates;
GO
-- this works
INSERT INTO Events(event_id, previous_event_end_date, event_start_date, event_end_date)
VALUES ('Glob Week', '2010-01-05', '2010-01-06', '2010-01-10');
-- this fails
INSERT INTO Events(event_id, previous_event_end_date, event_start_date, event_end_date)
VALUES ('Snoob', '2010-01-09', '2010-01-11', '2010-01-15'); 
What you did post is awful. Why did you append “->Destroyed” to an identifier? This is redundant AND destroys the integrity of the original encoding. Why do you use a local temp table? This mimics a  1950's scratch tape and no SQL programmer would use
it. Why would a note repeat another column? 
Please read this and try again. 
https://www.simple-talk.com/sql/t-sql-programming/state-transition-constraints/
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL

Similar Messages

  • I have installed CS5 on a macbook pro 10.9.4. I am unable to get the updater to run to update applications to most current version. It tells me there was an error trying to download the update and to try again later.

    I have installed CS5 on a macbook pro 10.9.4. I am unable to get the updater to run to update applications to most current version. It tells me there was an error trying to download the update and to try again later.

    Getting used to changes in the finder. I finally did see the Adobe Patch installer and am able to update applications individually. Should be able to attend to the main apps I use w/o further difficulty. Thnx for the help.

  • Hello! Just connected a used iPhone to iTunes for the first time. I'm trying to restore it to factory settings/default. The phone is connected via Wi-Fi and is updated to the most recent OS that the phone allows. The computer is also connected to the

    Hello! Just connected a used iPhone to iTunes for the first time. I'm trying to restore it to factory settings/default. The phone is connected via Wi-Fi and is updated to the most recent OS that the phone allows. The computer is also connected to the internet. But I still get the error: "itunes could not contact the iphone software update server because you are not connected to the internet." I also connected via iTunes and authorized the computer, but still have the same issue. Really, all I need to do is completely wipe the phone and start from scratch for safety's sake.
    Help?

    Did you check your security software settings?
    Third-party security software might conflict with iOS devices connecting to iTunes. Follow this article to troubleshoot issues that might be caused by your security software.

  • I had about 6000 pictures on my phone, then said "updating library" was not plugged into the computer, was at dinner trying to pull a picture up. After finished updating i only had 597 photos that were totally random, not in order...help?!

    I had about 6000 pictures on my phone, then said "updating library" was not plugged into the computer, was at dinner trying to pull a picture up. After finished updating i only had 597 photos that were totally random, not in order...help?!

    hi i had the same problem today when i updated my itunes to latest version. however, i have just found my songs in the 'itunes media' folder. this was accessed through 'my music'  then keep clicking through until you find itunes media and all my library songs were in there and i then just added these files to my library and all were restored however, i have lost all my playlists but at least my 700 songs are back. very dissapointed with apple that they have let this happen with their latest update, the previous version was miles better than this one . hope you find them. stevo

  • Query needs display only the recent record that was updated into BW.

    Hi Gurus,
    I have a question related to query creation.
    I hve one Infoset which was built on top of Opportunities data and Activities data cubes.  Tthey are linked using Opportunity GUID.  And in the query I am displaying the Opportunity ID(from Opportunity cube),  Sales order Number from the Activities data and a keyfigure No of Doc headers from the opportunities cube.  Everything is fine.  I want to display One Opportunity ID and One Activity associated with it.  I mean I want to display only the activity ID which is very recent.  But the query displays all the activity IDs which are associated with the opportunity ID.   We are not using any time characteristics too as the query has to display all the data that is there in the cubeI just want to see the recent activity that has got updated into the cube.  Kindly advice on how to achieve this..
    THanks in Advance
    Mohan Kumar

    Hi mohan,
    try to do some restriction by using  request ID (0requid) and variable 0S_RQMRC (Most current data on 0requid).
    for example a restriction on activiy id by most current request ID.
    hope it helps.

  • How to get Most current record in the reporting

    Hi All,
    I have reporting requiremnt  like to get the most recent record.
    Please see the below example we have 3 records but with 2 different sales represtentatives assigened to the same document.but i need to get most recently assigned sales representative record  that is number 2(10726056 and status open).
    Now i am geeting the 2 open records .Need to get only one.we do not have any other difference in the records to keep track of the sales representatives assignment to get the new sales rep id other than request id.
    Can any one tell me  most rcurrent data varibles under the request id do.Will it solves my issues o r any other ideas please welcome.
    Customer No    Sales rep    Doc number    Status     Request id
    0000613086    10726056    9000783660       C            REQU_1
    0000613086    10726056    9000783660       O            REQU_1
    0000613086    10182679    9000783660       O            REQU_2

    Hi Sirisha,
    it seems to be a problem of the kind "exception aggregation" , but let me say it can result in a very complex solution.
    What about using a Virtual Infoprovider with servicecs to solve the issue?
    You should create an additional InfoCube that reads form the basic one (where you have data) and then you should "delete" invalid records considering the request number.
    By the way time stamp seems to be the easier solution.
    Hope it helps
    GFV

  • Update once only.

    Hi,
    Can someone pls kindly advises me on how can i make the executeUpdate to update my data once only, that is, after it updated a row it should not execute again (exit from it)?
    By the way, i am using Excel as database and SDK1.3.1.
    Thanks for any kind advises.

    st.executeUpdate returns and integer u can hold that value and check
    2nd time
    int count=0;
    if(count>0)
    //dont update
    else
    //update
    count=st.executeUpdate()
    //so this part will be execute once only
    }

  • What's the most current version that runs on SP1?

    I need to find the most current version of QuickTime that will run on SP1. It is a work laptop and our IS department is reluctant to install SP2 on our systems, but I need to have QuickTime for an upcoming presentation that I am supporting. So any suggestions?

    iPhoto 11, v9.4.3.
    If you don't have iPhoto 11 already then you'll need to purchase an iLife 11 install disk, install the app and then update it.
    You may be able to purchase an iLife 11 disk on ebay or amazon.

  • HOW TO ENABLE FIELD ONLY IN CURRENT RECORD?

    I have a field in a multi record block that i want protected when user is editing a record. The problem is if the user wants to add a record they need to be able to enter a value for that field. My questions is how do you unprotect the field for the current record to be inserted without unprotecting the existing records in the block with the same field.
    Also, I want to clear a record in multi record block after it fails validation. What trigger would be ideal for such an operation or what method? I have a field that if they enter a duplicate value when doing an iserting I give an error to change. If they blank the field out(the user decided that they are not going to perform an insert) it seems that the record remains even though there are no values for the record. I am hoping that the user would not have to press a delete button that performs a delete_record but instead I can call clear_record to actually get rid of it. Thanks.

    Hi ,
    If you wish to hide or show fields, proceed as follows(through screen variants):
    1. Determine the screen variant, for example, BBP_SC(For shopping cart), using the list in documentation of BADI BBP_SCREENVARIANT.
    2. Copy this screen variant, for example, in Zbbp_SC, in Transaction SHD0.
    3. Change the new screen variant as required. Note that you can only change the display properties for fields of table controls. You can switch the display on and off.
    4. Implement the appropriate method (see the list above). Fill the export parameter EV_SCVARIANT with the new screen variant.
    You can create multiple screen variants for a screen and then select these in the BAdI depending on the user or on other criteria.
    here is sample code in BADI BBP_SCREENVARIANT implementation after creating Z screen variant.
    Method IF_EX_BBP_SCREENVARIANT~GET_SCREENVARIANT_SC.
    IF iv_progname EQ 'SAPLBBP_SC_UI_ITS'
    AND iv_dynnr EQ '0120'
    AND flt_val EQ c_fltval.
    IF iv_scvariant EQ 'BBP_SC'.
    ev_scvariant = 'Zvariant'.
    ENDIF.
    ENDIF.
    ENDMETHOD.
    Please reward points if helpful..
    Thanks
    Venkatesh

  • Why does Firefox want to update to the most current version upon starting when I have already updated?

    Upon starting Firefox, often after starting or restarting my computer but sometimes after closing the Firefox browser(s) for a significant time, the program asks to update. Firefox asks this every time, and I have no idea how many times I have updated to the most recent browser version and I suspect the update is not saving correctly so the program is continually reverting to the last recent browser version.

    There are no useragent prefs listed in the System Details List and extensions.lastAppVersion: 15.0.1 suggests also that you run Firefox 15.0.1.
    Do a clean reinstall and delete the Firefox program folder before (re)installing a fresh copy of the current Firefox release.
    Download a fresh Firefox copy and save the file to the desktop.
    *Firefox 26: http://www.mozilla.org/en-US/firefox/all.html
    if possible uninstall your current Firefox version to cleanup the Windows registry and settings in security software.
    *Do NOT remove personal data when you uninstall your current Firefox version, because all profile folders will be removed and you lose personal data like bookmarks and passwords from profiles of other Firefox versions.
    Remove the Firefox program folder before installing that newly downloaded copy of the Firefox installer.
    *(32 bit Windows) "C:\Program Files\Mozilla Firefox\"
    *(64 bit Windows) "C:\Program Files (x86)\Mozilla Firefox\"
    *It is important to delete the Firefox program folder to remove all the files and make sure that there are no problems with files that were leftover after uninstalling.
    *http://kb.mozillazine.org/Uninstalling_Firefox
    Your bookmarks and other personal data are stored in the Firefox profile folder and won't be affected by an uninstall and (re)install, but make sure that "remove personal data" is NOT selected when you uninstall Firefox.
    If you keep having problems then also create a new profile.
    *http://kb.mozillazine.org/Profile_folder_-_Firefox
    *http://kb.mozillazine.org/Profile_backup
    *http://kb.mozillazine.org/Standard_diagnostic_-_Firefox#Clean_reinstall

  • I have version 3.5.11 and want to update to the most current firefox. I download but when I try to put it in my Mac applications, it says I dont have permission to access some of the items.

    I have a Mac with snow leopard. I am using firefox 3.5.11 and want to install the most current version. I downloaded it and when I try to drop it on my applications it says I don't have permission to access some of the items.
    == This happened ==
    Every time Firefox opened
    == I treid to update

    Hello Curly59,
    ''"do you want to replace the newer version that is already installed with this older one?" ''
    it is correct
    1. Download a copy of the latest firefox from http://www.mozilla.org/en-US/firefox/all.html
    2. '''Trash''' the current Firefox application to do a clean install.
    3. Install the version that you have downloaded.
    Do not select to remove your personal data, your profile data is stored elsewhere in the [http://kb.mozillazine.org/Profile_folder_-_Firefox Firefox Profile Folder], so you won't lose your bookmarks or other personal data.
    see also: [https://support.mozilla.org/en-US/kb/install-firefox-mac?redirectlocale=en-US&redirectslug=Installing+Firefox+on+Mac#os=mac&browser=fx19 Installing Firefox on Mac]
    thank you

  • How to read only the most current records in PL/SQL

    Oracle version: 11.2
    I have a table in ORACLE called RATES and there is a EFFECTIVE_DATE, RATE_NAME, RATE_AMOUNT
    RATE
    1 RATE_ONE 1/1/2000 0.10
    2 RATE_ONE 5/1/2005 0.15
    3 RATE_ONE 12/1/2010 0.20
    4 RATE_TWO 10/15/2009 0.33
    5 RATE_THREE 9/7/2011 0.05
    6 RATE_THREE 12/31/2011 0.06
    A rate can be in there multiple times, but the most recent rate is the active rate. I need to query this table and only want to bring back the currently active rows:
    RECORDS 3, 4 and 6
    How can I do this in the most elegant way?
    Can I say:
    SELECT RATE WHERE trunc(sysdate) between EFFECTIVE_DATE and trunc(sysdate);
    (this will not work. I'm not sure how to do this without an exp date column and then I could say
    SELECT RATE WHERE trunc(sysdate) between EFFECTIVE_DATE and END_DATE
    The problem is that I cannot add that column at this time, so need to find a way to do it programatically
    Edited by: userLynx on Feb 1, 2012 8:56 AM

    Try This:
    WITH a
            AS (SELECT 'RATE_ONE' ratename,
                       TO_DATE ('1/1/2000', 'mm/dd/yyyy') eff_date,
                       0.10 amount
                  FROM DUAL
                UNION ALL
                SELECT 'RATE_ONE' ratename,
                       TO_DATE ('5/1/2005', 'mm/dd/yyyy') eff_date,
                       0.15 amount
                  FROM DUAL
                UNION ALL
                SELECT 'RATE_ONE' ratename,
                       TO_DATE ('12/1/2010', 'mm/dd/yyyy') eff_date,
                       0.20 amount
                  FROM DUAL
                UNION ALL
                SELECT 'RATE_TWO' ratename,
                       TO_DATE ('10/15/2009', 'mm/dd/yyyy') eff_date,
                       0.33 amount
                  FROM DUAL
                UNION ALL
                SELECT 'RATE_THREE' ratename,
                       TO_DATE ('9/7/2011', 'mm/dd/yyyy') eff_date,
                       0.05 amount
                  FROM DUAL
                UNION ALL
                SELECT 'RATE_THREE' ratename,
                       TO_DATE ('12/31/2011', 'mm/dd/yyyy') eff_date,
                       0.06 amount
                  FROM DUAL)
    SELECT ratename, eff_date, amount
      FROM (SELECT ratename,
                   eff_date,
                   amount,
                   RANK () OVER (PARTITION BY ratename ORDER BY eff_date DESC) rk
              FROM a)
    WHERE rk = 1

  • CC will not update to the most current version. Is my OS to old?

    I'm was attempting to setup an AE render farm on 2 machines running OSX 10.7.5. Each machine has hit the wall of being able to update the OS anymore. The version of AE render engine is 12.1. My newer machine is running Mavericks and has the most resent version of AE (12.2) installed. After I figured that out it was easy to understand why my render farm wasn't working.
    Are my 2 Apple machines just too old?

    Hello Todd. Thanks for all your help.
    I tried the manual updater and that failed as well.
    Here is the error I get -
    Update Failed
    Updates could not be applied
    This patch is not applicable for you. Please check for updates from the Help menu in you product to see a list of latest updates available.
    Also you asked before if I am running in trial mode. I don't believe so, I have a membership to Creative Cloud.
    I also checked the specs on each computer and they meet the recommended specifications.
    Do you know of anything else that would be causing this failure to update problem?

  • My atv won't update to the most current firmware.

    So I turned on my apple tv (2nd gen) today for the first time in a couple months and it said that there was a software update available to install. After trying to install and download it multiple times it still won't let me. I keep getting the error message "the update wasn't successful." I don't know really what to do. My Internet has been acting up a little bit lately but I would think that I would still be able to be able to download and install it after a few different tries. Thanks

    Welcome to the Apple Community.
    There are issues with the update servers at the moment, I can only suggest you keep trying.

  • I want to change my primary email to my most current email but it keeps saying there is already an apple ID for that email, how do I delete that one so I can use all of my old information, just with my most current email address?

    I created the apple ID that I currently have about 6 years ago and I want to change my primary email from my childish one to my most current email that I constantly use, but I think I accidentally created an apple ID with that email, I want to delete that apple ID so that I can just plug my new email in with all of my old information (that is still the same).  I am so lost

    I don't believe Apple lets you delete old accounts. They also will not let you merge them.

Maybe you are looking for

  • Why does InDesign sometimes NOT package fonts?

    Hi. I'm using the latest version of InDesign and lately, when I package files, I've noticed that the 'document fonts' folder is not always created in the finished packaged folder. There seems to be no pattern to when it does or does not include them.

  • PO output

    Hi friends, I am configuring output types for PO's. I have a vendor needs outputs through Fax and sometimes through print outs. I am using the NEU output. When i try to create condition records for NEU with medium 2(fax), system is giving a message T

  • Mail Profile Operators Not Available

    SQL Server v.11.0.3321; OS 2008 R2 SP1.  We setup the Agent Operator, but when trying to add the Operator to the SQL Server Agent's Alert System, there is nothing under the Mail Profile drop-down list. So the Enable Mail Profile checkbox is accessibl

  • Decreasing latency and increasing down/up speeds

    My latency is usually between 30ms and 50ms. My speed is 2454kbps down and 350kbps up. It's really hard to do some good gaming at those speeds and especially with that kind of latency. I'm running through my wireless router. I'm on a Buffalo WHR-G54S

  • Cable for ipod - HELP!!!

    I was looking at purchasing the XtremeMac Auxiliary Audio Cable for iPod and I just want to be clear that I am understanding the description correctly. Do you plug the cable into your ipod (where the headphones go) and also into your stereo (also whe