Help in Update script

Hi, How I can update the SEQUENCE column in Seq_Order column in one update script. It shoud be decrease by -1. Thanks.
Current Data of Seq_order table
SEQUENCE   SEQ_No
24               300
NULL            301
NULL            302
NULL            303
NULL            304
NULL            305
--Desired Output
SEQUENCE   SEQ_No
24               300
23              301
22             302
21             303
20             304
19            305

-----SQL Server 2012, 2014
create table test3 (SEQUENCE int, SEQ_No int)
insert into test3 values(24,300),(null,301),(null,302),(null,303),(null,304),(null,305)
;with mycte as (
select Sequence, mySum - sum(cnt) Over (Order by SEQ_NO)+ 1 as [SequenceNew] , SEQ_No from
select * , sum(SEQUENCE) Over (Order by SEQ_NO) mySum
, count(SEQUENCE) Over(Order by SEQ_NO) cnt from test3) t )
Update mycte
Set Sequence=[SequenceNew]
select * from test3
drop table test3

Similar Messages

  • Need help with update query

    I am having a strange problem with an update query I am running. Here are the specifics:
    1. I run a script that extracts qualifying rows form a source table (S1), performs some calculation,s and stores the results in a temporary table (T1).
    2. The calculations stored in the temporary table (T1) are only for a subset of rows in the source table (S1).
    3. The temporary table (T1) uses the same primary key values as the source table (T1).
    4. Once the calculations are completed, I want to update a single column on the source table (S1.CalcValue) with the calculated value from the temporary table (T1.CalcValue).
    The problem is that I am doing monthly updates so I run month 1, do some verification of the data and then update the source table. Then repeat the process for months 2 through n. When I run the update for the month 2 data, the prior month 1 data for the column is lost. Below is the update script which looks like it should work and only update on the matching keys between the temporary table (T1) and the source table (S1). I was wondering if anyone could let me know what is wrong with this script and why.
    I am new to Oracle having worked extensively in SQL Server, so the syntax differences are killing me right now so any help would be appreciated.
    Update script:
    procedure update_rvu AS
    BEGIN
    --update the test.RVU table
    update test.RVU S1
    set S1.CalcRVU = ( select
    T1.CalcRVU
    from
    TMP_RVU T1
    where
    S1.GroupId = T1.GroupId
    and
    S1.PatientId = T1.PatientId
    and
    S1.InvoiceId = T1.InvoiceId
    and
    S1.TransId = T1.TransId
    commit;
    END update_rvu;
    Edited by: user9009311 on Apr 14, 2010 4:47 PM

    Most likely you want a WHERE clause in your update portion ... something like
    update test.RVU S1
    set S1.CalcRVU = ( select
    T1.CalcRVU
    from
    TMP_RVU T1
    where
    S1.GroupId = T1.GroupId
    and
    S1.PatientId = T1.PatientId
    and
    S1.InvoiceId = T1.InvoiceId
    and
    S1.TransId = T1.TransId
    where exists
       select null
       from tmp_rvu t11
       where S1.GroupId = T11.GroupId
       and    S1.PatientId = T11.PatientId
       and    S1.InvoiceId = T11.InvoiceId
       and    S1.TransId = T11.TransId
    )You can also look into using the MERGE command (if you're on version 10 or better you can perform update only operations with it). I personally find it more 'friendly' than correlated updates a lot of the time.

  • Update fails (Failed to run database update script)

    Still unable to update my zmm. it fails to uppgrade the sqldb.
    logfiles ends like this.
    Msg 512, Level 16, State 1, Server xxxxx, Procedure , Line 2
    [Microsoft][ODBC SQL Server Driver][SQL Server]Subquery returned more than 1
    value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or
    when the subquery is used as an expression.
    The statement has been terminated.
    1> 2> 3> 4> 5> 6> 7> [17:04:44] RunShellCommand: Command: osql exited with code: 1
    [17:04:44] RunShellCommand: Exit code indicates failure.
    [17:04:44] UpdateDatabase: Failed to run database update script.
    Need some help plz

    dahlholm,
    It appears that in the past few days you have not received a response to your
    posting. That concerns us, and has triggered this automated reply.
    Has your problem been resolved? If not, you might try one of the following options:
    - Visit http://www.novell.com/support and search the knowledgebase and/or check all
    the other self support options and support programs available.
    - You could also try posting your message again. Make sure it is posted in the
    correct newsgroup. (http://forums.novell.com)
    Be sure to read the forum FAQ about what to expect in the way of responses:
    http://forums.novell.com/faq.php
    If this is a reply to a duplicate posting, please ignore and accept our apologies
    and rest assured we will issue a stern reprimand to our posting bot.
    Good luck!
    Your Novell Forums Team
    http://forums.novell.com

  • Run e-tester from a server and have staff remotely update scripts

    Can we run the floating e-tester from a server and have staff remotely access the server to run and update scripts instead of installing the client on everyone's workstation?

    Original Question:
    Can we run the floating e-tester from a server and have staff remotely access the server to run and update scripts instead of installing the client on everyone's workstation?
    There are different alternatives to consider and different ways to answer the question.
    1) You can run e-Tester with a floating license from a server and have people to use remote desktop to run and create scripts.
    Pros:
    * Multiple users can be updating scripts in the server at the same time.
    * There is no need to install e-Tester in any other computer.
    Cons:
    * If the max number of floating licenses is reached no other person can open another instance of e-Tester.
    * Having multiple people running scripts in the Job scheduler will create conflicts therefore is not recommended. Running multiple instances of e-Tester manually shouldn't cause problems, but it is a slow way to do regression testing. The job scheduler can run a script after another without user intervention. Teamwork can be affected if the default settings are changed by different users.
    * Running thru remote desktop(or any other remote tool such as vnc) is slower than having etester in the computer. The refresh rate of the screen tends to be slower.
    * If multiple users are using the server resources at the same time it can slow down the work of others. The server can run out of memory or it will be slow because the CPU running near max capacity.
    2) You can run eTester with a node lock license from a server and have people to use remote desktop to run and create scripts.
    Pros:
    * Multiple users can be updating scripts in the server at the same time.
    * There is no need to install eTester in any other computer.
    * Only one license is required.
    Cons:
    * Having multiple people running scripts in the Job scheduler will create conflicts therefore is not recommended. Running multiple instances of etester manually shouldn't cause problems, but it is a slow way to do regression testing. The job scheduler can run a script after another without user intervention. Teamwork can be affected if the default settings are changed by different users.
    * Running thru remote desktop(or any other remote tool such as vnc) is slower than having etester in the computer. The refresh rate of the screen tends to be slower.
    * If multiple users are using the server resources at the same time it can slow down the work of others. The server can run out of memory or it will be slow because the CPU running near max capacity.
    Notes:
    1) Having eTester installed in each individual's computer will allow the person to run tests with no worries about conflicts of server resources or job schedules trying to start an etester instance. Installing etester is a one time thing that takes in general less than 10 minutes.
    2) Instead of sharing the server resources you can share the place where the scripts reside. You can place the scripts in a central location and and configure etester to read the scripts from there. Instructions on how to do this should be in the knowledge base (if not please let me know)(Don't be lazy Zuriel, paste the link here).
    3) You can consider to have eManager Enterprise if you want to have better organization of the scripts. In eManager Enterprise you can relate your test cases to your scripts, you can run the scripts from a central location, it is less limited for scheduling scripts than the JobScheduler, and it can be accessed from anywhere inside the company with a web browser (for security reasons requires username and password). eManager Enterprise doesn't have the ability to create or update scripts, it uses scripts that were created in eTester already.
    eManager can also create schedules conflicts if multiple runs are attempted. There are ways to deal with this situation by having multiple computers to run the tests. (Please post in another thread if more information is necessary).
    I hope this helps.
    Regards,
    Zuriel

  • HT4623 please help me update ios 4.3 in iphone 3g

    please help me update ios 4.3 in iphone 3g

    You can't. The iPhone 3G can only go as high as iOS 4.2.1. It hardware does not suport a higher iOS.
    BW this is the iPod touch forum.

  • Tabs only open in a new window. Ctl T opens a new window NOT a new tab help-last update this problem started. How do I set FF back to open tabs in 1 window

    Tabs only open in a new window. Ctl T opens a new window NOT a new tab help-last update this problem started 2 days ago. How do I set FF back to open tabs in 1 window?
    There is no plus sign and going into optins and changing settings has not worked. I have uninstall FF and reinstall-keeping my personalization-and that was no help.
    Right clicking on FF Icon to open a new tab, or going up to FF drop down tab and clicking on new tab both do not work.
    Help everything opens a new window not a new tab. there seems to be no way to reset this or to chose a different optin. I just downloaded new tabs at end addon and it didn't do a thing.

    as a first troubleshooting step - does it work like normally when you open & run firefox in [[Safe Mode|safemode]] by pressing the shift key while you open firefox (all other instances have to be closed before)...

  • Need help in creating script for "Task Schedule" in Oracle E-Bussiness Suit

    Hi,
    I need some urgent help regarding the scripting of Oracle E-Business Suite application. I am new towards working on Oracle Applications. I have been using LoadRunner 11.0 and protocol oracle applications 11i for the scripting of the application. The problem is as follows:
    Scenario- Schedule an incident to a resource.
    1) Log in to the application.
    2) Open Oracle Forms Page.
    3) Enter the details of the incident number.
    4) Right click on the incident number and then select “schedule” option.
    5) Check / Select the resource listed in the new form.
    6) Click on “schedule” Button.
    7) Exit the oracle forms.
    8) Logout from the application.
    I have recorded the scenario but when I try to run the script, it fails after completing the 4th step from the scenario mentioned above. I have done all the required co-relations..
    Another issue that I have noticed in the scipt is that it records a lot of requests to the AppsTCFServer.
    When I check the Tree View of the script, I have found that there are around 25 requests to the AppsTCFServer recorded in the script. In the header of these requests a TCF Start/Session number gets generated randomly. This number stays the same in few AppsTCFServer request headers and then a new number gets generated and the cycle continues.
    However LoadRunner does not generate this number by itself during replay. I cannot find this number in any previous responses.
    In the last few days, I have tried my hands on Oracle Openscript tool to record the above scenario, but still I am getting the same problem, i.e instead of getting the correct response from the server for the AppsTCFServer requests, I am getting the message "X-session 7098.... not found - aborting ".
    I get this message whether I use LoadRunner tool or the OpenScript tool.
    Please help me solve this issue.
    Thanks & Regards,
    Soumya Mukherjee

    This isn't much of a "code-sharing" site but a "knowledge-sharing" site.  Code posted me may be from a questioner who has a problem / issue / error with his code.   But we don't generally see people writing entire scripts as responses to such questions as yours.  There may be other sites where you can get coding done "for free".
    What you could do is to write some of the code and test it and, if and when it fails / errors, post it for members to make suggestions.
    But the expectation here is for you to write your own code.
    Hemant K Chitale

  • Need help in UPDATE data in SQL Query

    Hi all,
    I am trying to update data in the sql table as per below screenshot but couldn't able to do it. Can anyone help to update the data as I mention in screenshot.Appreciate you help.Thanks.
    Yellow highlighted columns are source
    Green highlighted columns are target
    Colored data should be update as per source data in sql table.Data is not static as it might have more rows to update and query should be bit dynamic.
    Maruthi...

    You have already asked this question once. You did not get any good answers, because you the information you gave was insufficient. And I'm afraid that the information is still in sufficient.
    Or more exactly, from the example you have given, the answer is: can't be done. And the reason it can't be done, is as I explained in response to you first thread: there is no information in the data to from which we can deduce that Clorox Company
    should be under "Week 1-1,K.B,F". The fact that rows are listed in a certain order in the screenshoot is of no importance, because a table is an unordered object.
    But you said in another post that you have a timestamp column. Maybe that column is usable - maybe it is not. But at least it is a key that you have more columns that the ones you show.
    The best way to get help with this type of problems is to post:
    1) CREATE TABLE statement for your table(s).
    2) INSERT statements with sample data.
    3) The desired result given the sample.
    4) A short description of the actual buisness problem you are trying to solve.
    5) Which version of SQL Server you are using.
    This makes it easy to copy and paste into a query window to develop a tested solution. Screenshots with an insufficient amount of data is not going to help you very much.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • HELP! Updated to keynote 9...created a presentation (took me hours) and now it won't open and i'm being told I have to 'buy' the new keynote to open it

    HELP! Updated to keynote 9...created a presentation (took me hours) and now it won't open and i'm being told I have to 'buy' the new keynote to open it

    Keynote 6 is compatible with Mavericks only, your profile states you are using Snow Leopard, if thats the case use Keynote version 5 and all will work as before.

  • MAC OS 10.6.8 Using Safari 5.1 Needing Help With Updating Adobe Flash

    Hello-
    Recently Adobe Flash installed an icon in my System Preferences and when I click the icon there are several tabs.  One allows updates to check automatically.  It says it will install the latest version of Flash without having to remove the previous version, but I have never been told that a newer version is available unless I clcik "check now."  although "Check for updates automatically" is checked, I do not know where it tells me a newer version is available.  Also, there has been 5 "newer versions" available since this icon was installed in System Prefeences, I have only found out about the newer versions when I clicked "Check Now."  If I read that with this new way to install the latest Mac version of Flash does not require me to uninstall the previous version of Flash how do I install the most recent version of Flash?  Does it come in an email?
    Since it is not telling me that there is a more recent version of Flash unless I click "Check Now" should I still do it the way I used to install the latest version of flash?  (The way before this icon was added to System Preferences)?
    I would appreciate help with updating Flash to the most recent version.  I used to uninstall the older version, restart the browser and download the most recent version and install it.  It always worked find but this was before there was an Adobe icon in my system Preferences.

    Hello,
    The way you used to do this (uninstall, restart the browser, etc.) is still definitely valid and probably the "safest" way to get a new version installed.  Uninstalling shouldn't be required, but it definitely doesn't hurt.  If you feel comfortable doing it the old way, please feel free to continue using that process.
    As for notifications, this is a bit trickier, but in general you should be notified within 30 days (or so) after a new player is released.  This usually occurs when the browser loads swf content.  Clicking the button will, like you mention, immediately check.  Another alternative to finding out when a new player is released is to subscribe to our Flash Player Releases feed.
    Is there a way to be automatically notified when a new Flash Runtime release is made?
    Thanks,
    Chris

  • Help after updating the OS to 4.3.3 none of the 3rd party app work

    Help after updating the OS to 4.3.3 none of the 3rd party apps work at all they just flash up on the screen and then die.

    install a free app (or any other app) from the app store, then the problem will be fixed.

  • Help I updated my phone to 5.1.1

    help I updated my phone to 5.1.1 and now i cant put music on it

    What happens when you try?

  • Update script taking long time....

    Dear all,
    I have to update more then 2 mil records in a table but below update script took whole day still did not finish, is there any other way to enhance this update statement.
    update  customer_table  p
      set P.ic_no   = fn_change_iden_no_dirct(p.v_ic_no, p.ic_code)
      where P.ic_no is not null
    " fn_change_iden_no_dirct"  is a finction which returns the correct ic_no?
    BELOW IS THE COSTING OF THE ABOVE UPDATE SCRIPT
    ID     PID     Operation     Name     Rows     Bytes     Cost     CPU Cost     IO Cost
    0          UPDATE STATEMENT     2292K     34M     1192            1192
    1     0     UPDATE CUSTOMER_TABLE                              
    2     1       TABLE ACCESS FULL  CUSTOMER_TABLE     2292K     34M     1192       1192
    .....Thank you

    One reason the update is slow is because Oracle will do two switches between the SQL engine and the pl/sql engine for each row that it has to process. Such a switch usually is very slow. In 11g you could profit from funcion result cache. But the best way would be not to use a user-defined pL/sql function.
    I just noticed that you will do 4 context switches because inside of your function you do a not needed SELECT to get the length.
    First thing I would do is replace
    BEGIN
          select length(trim(PI_INSTR))
          into lv_length from dual;
    ...with
    BEGIN
          lv_length := length(trim(PI_INSTR));
    ...Here is a version where I tried to copy the logic from your function to the SQL statement. Also note that I tried to update only those rows that require a change.
    starting point
    update  customer_table  p
      set P.ic_no   = fn_change_iden_no_dirct(p.v_ic_no, p.ic_code)
      where P.ic_no is not null
      and P.ic_no  != fn_change_iden_no_dirct(p.v_ic_no, p.ic_code)
    changed logic
    update  customer_table  p
      set P.ic_no =
            decode(p.ic_code
                       /* NEW IC part */
                       ,'NEWIC', case when  length(trim(p.v_ic_no)) = 12
                                       then substr(trim(p.v_ic_no),1,6)||'15'||'999'||substr(trim(p.v_ic_no),12,1)
                                       when length(trim(p.v_ic_no)) > 12
                                       then substr(trim(p.v_ic_no),1,6)||'15'||'999'||substr(trim(p.v_ic_no),-(length(trim(p.v_ic_no)) -11))
                                       when length(trim(p.v_ic_no)) between 8 and 11
                                       then substr(trim(p.v_ic_no),1,6)||'15'||'999'
                                       else p.v_ic_no
                                 end
                       /* IC part */
                       ,'UIC', case when  length(trim(p.v_ic_no)) > 4
                                       then substr(trim(p.v_ic_no),1,1)|| substr(trim(p.v_ic_no),4,1)||substr(trim(p.v_ic_no),3,1)||substr(trim(p.v_ic_no),2,1) ||substr(trim(p.v_ic_no),- (length(trim(p.v_ic_no)) -4))
                                       else p.v_ic_no
                                 end
                       /* else part */
                       ,p.v_ic_no)
      where P.ic_no is not null
      and (p.ic_code in ('NEWIC','UIC')  or   p.v_ic_no !=  P.ic_no)
       ;Edited by: Sven W. on Jul 5, 2010 1:35 PM

  • Need help in Java Script

    i Need some help in Java Script,
    am using the following code :
    <script type="text/javascript">
    var newwindow;
    function poptastic(url)
    newwindow=window.open(url,'name','height=300,width=400,left=100, top=100,resizable=yes,scrollbars=yes,toolbar=yes,status=yes');
    if (window.focus) {newwindow.focus()}
    else {newwindow.close()}
    //     if (window.focus) {newwindow.focus()}
    </script>
    In HTML,
    thWorld Environment
    Day, June 5<sup>th</sup>,2005
    Am using onmouseover event, so that when my mouse in on the link, popup is opened....and when my mouse is out of the link, the new window should b closed....
    but according to the above code, the new window is opened but have to close it manually....
    Is there any other way to close the popup when my mouse is out of the link

    Prawn,
    This is not really a good way to make friends. With the cross posting and the posting in a wrong forum anyway thing you have going.
    Please kindly take your question to an appropriate JavaScript forum.
    Have a happy day.
    Cross post from http://forum.java.sun.com/thread.jspa?messageID=3797201

  • Need a help on Update statement

    Hi All,
    I Need a help in updating a table column. PFB my requirement.
    Table1
    ItemID OrgId       Date
    1       82     12/sep/2012   
    2       82     25/oct/2012
    3       82     17/Nov/2012
    4     82     22/Jan/2013
    5     82     26/sep/2012
    Table2
    Itemid     orgid       Date1
    1      82     23/sep/2012      
    2      82     25/Dec/2012
    3      82     17/Sep/2012
    4      82     22/Feb/2013
    5      82     26/Oct/2012
    Table3
    Itemid     orgid       Date3
    1      82     10/sep/2012      
    7      82     30/Dec/2012
    3      82     12/Sep/2012
    10      82     27/Feb/2013
    5      82     29/Oct/2012
    I Need to Update Date column of Table1 With Date3 of table3
    If
    Item and org combination is present in table3 and date column of table1 is less than Date3 of table3
    Else
    I need to Update with date2 of table2.Can we acheive this in a single update statement, can any one help me on this.
    Thanks and regards,
    Rakesh
    Edited by: Venkat Rakesh on Sep 27, 2012 11:04 PM

    You can probably also use MERGE:
    --DROP TABLE table1;
    --DROP TABLE table2;
    --DROP TABLE table3;
    ALTER SESSION SET nls_language = 'AMERICAN';
    CREATE TABLE table1
       itemid    CHAR (1),
       orgid     CHAR (2),
       thedate   DATE
    INSERT INTO table1   SELECT '1', '82', TO_DATE ('10/sep/2011', 'dd/mon/yyyy') FROM DUAL;
    INSERT INTO table1   SELECT '2', '82', TO_DATE ('10/oct/2011', 'dd/mon/yyyy') FROM DUAL;
    INSERT INTO table1   SELECT '3', '82', TO_DATE ('10/nov/2011', 'dd/mon/yyyy') FROM DUAL;
    INSERT INTO table1   SELECT '4', '82', TO_DATE ('10/jan/2011', 'dd/mon/yyyy') FROM DUAL;
    INSERT INTO table1   SELECT '5', '82', TO_DATE ('10/sep/2011', 'dd/mon/yyyy') FROM DUAL;-- won't be updated
    CREATE TABLE table2
       itemid    CHAR (1),
       orgid     CHAR (2),
       thedate   DATE
    INSERT INTO table2   SELECT '1', '82', TO_DATE ('01/sep/2012', 'dd/mon/yyyy') FROM DUAL;
    INSERT INTO table2   SELECT '2', '82', TO_DATE ('01/dec/2012', 'dd/mon/yyyy') FROM DUAL;
    INSERT INTO table2   SELECT '3', '82', TO_DATE ('01/sep/2012', 'dd/mon/yyyy') FROM DUAL;
    INSERT INTO table2   SELECT '4', '82', TO_DATE ('01/feb/2012', 'dd/mon/yyyy') FROM DUAL;
    CREATE TABLE table3
       itemid    CHAR (1),
       orgid     CHAR (2),
       thedate   DATE
    INSERT INTO table3   SELECT '2', '82', TO_DATE ('30/dec/2009', 'dd/mon/yyyy') FROM DUAL; -- date less than table1, so picks from table2
    INSERT INTO table3   SELECT '4', '82', TO_DATE ('30/mar/2013', 'dd/mon/yyyy') FROM DUAL; -- larger than table1 , so pick this date
    -- table1 original data
    SELECT * FROM table1;
    -- merge new data
    MERGE INTO table1
         USING (SELECT NVL (t1.itemid, t2.itemid) itemid,
                       NVL (t1.orgid, t2.orgid) orgid,
                       t2.thedate prefdate ,
                       t1.thedate nextdate
                  FROM    table2 t1
                       FULL OUTER JOIN
                          table3 t2
                       ON t1.itemid = t2.itemid AND t1.orgid = t2.orgid) dat
            ON (dat.itemid = table1.itemid AND dat.orgid = table1.orgid)
    WHEN MATCHED
    THEN
       UPDATE SET table1.thedate = (case when prefdate > table1.thedate then prefdate else nextdate end) ;
    --table1 updated data
    SELECT * FROM table1;OUTPUT:
    Session altered.
    Table created.
    1 row created.
    1 row created.
    1 row created.
    1 row created.
    1 row created.
    Table created.
    1 row created.
    1 row created.
    1 row created.
    1 row created.
    Table created.
    1 row created.
    1 row created.
    ITEMID ORGID THEDATE  
    1      82    10.09.2011
    2      82    10.10.2011
    3      82    10.11.2011
    4      82    10.01.2011
    5      82    10.09.2011
    5 rows selected.
    4 rows merged.
    ITEMID ORGID THEDATE  
    1      82    01.09.2012
    2      82    01.12.2012
    3      82    01.09.2012
    4      82    30.03.2013
    5      82    10.09.2011
    5 rows selected.

Maybe you are looking for

  • Xi adapter framework

    hello I have a scenario RFC 2 WS sync and the message does not leave the XI to the WS. the message that I see in the sxmb is   <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> - <!--  Call Adapter   --> - <SAP:Error xmlns:SAP="http://sap.com/

  • Can I open Photoshop Action files in Fireworks CS5?

    Hi, I need to confirm that this is okay before buying something! Thanks

  • Dual monitors in photoshop elements 11

    how can i use dual monitors in photoshop elements 11 in photoshop elements 9 i can simply drag the open file over to the other monitor

  • To get bulb in the pop up messages

    Hi friends, i am using popup_to inform function module. it throws only messages. I want to give Bulb (yellow) with  message to be displayed . i know code for red bulb that is '@0A@ MESSAGE' But for yellow colour i tried but it is not coming.. if any

  • MissingResourceException using ResourceBundle

    I'm developing an app based on the Duke's bank app in J2sdkee 1.3 Tutorial. I get the following IE 5.0 browser error when I try to access the "main" page. A Servlet Exception Has Occurred java.util.MissingResourceException: Can't find bundle for base