Query for Updation!!!

Hi,
I am working on some retail related.our client is having some vendors.so every month we are calculating the total sales about the products.
Means we have "TotaL Current Sales" and Prevous "Month sales amt".
By using these two we are preparing statements for that particular vendor for that particular month and the previous month.
But the problem is am getting... when I am tryiyng to update the Previous MOnth amt it is getting updated but while preparing the statement it is showing the old value instead of new value.
can you please help me out to resolve it.
Eg : Current Month sales : 23,000,000
Previous MOnth Sales : 13,000,000
Here I have written the update statement to update the Previous month sales as 11,000,000.
then it is showing the sales as 11,000,000.
But while preparing the statement it is showing the Previous month sales as 13,000,000 only.But I want to display it as 11,000,000.
can you please help me out to write a query or Procedure/Function or any thing which is required for this.
Thanks in advance.

Give us the following details.
1. DB Version.
2. Table structure
3. Sample Data
4. SQL Statement Executed by You.
Use {noformat}{noformat} tags when you post the above details to preserve the code format.
You can use it like this
<your code here>\                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • SQL Query for update

    hi experts
    I got two tables
    BOOK (DDC,TITLE,ISBN,AUTH_NAME)
    AUTHOR (ID,DDC,AUTH_NAME)
    AUTH_NAME column in BOOK's table contains NULL for all records.
    I want update table BOOK's column AUTH_NAME from AUTHOR's column in AUTHOR table where DDC numbers match. DDC is not unique in AUTHOR's table. I want to update BOOK table with the first matching AUTH_NAME. Rest should be ignored.
    Please write me the query for it.
    thanks

    Please write me the query for it.This fellow has no questions.
    Please, DO NOT ANNOY HIM with hints and tips, he just wants his answer. ; )
    I suspect it's homework, just another cheating student, earning his OCP.
    He is very anxious to get somebody to do his work, as he has spammed this same questtion on several other Oracle forums:
    http://dba.ipbhost.com/index.php?showtopic=10441
    http://www.dba-village.com/village/dvp_forum.OpenThread?ThreadIdA=32264

  • Parallel query for UPDATE

    Hi,
    In the documentation of Oracle 10.2 -> Data Warehousing guide -> Ch.25 Using Parallel execution, search for section labeled "Rules for UPDATE, MERGE and DELETE", it is mentioned that,
    "UPDATE, MERGE, and DELETE operations are parallelized by partition or subpartition. Update, merge, and delete parallelism are not possible within a partition, nor on a nonpartitioned table"
    I am on 10.2 Enterprise edition, Solaris. I can see that, I can parallelize an UPDATE command (commands pasted below).
    Please can somebody explain me, what am I missing ??
    SQL> drop table r1 ;
    Table dropped.
    SQL> create table r1 as select * from user_objects where 1=2 ;
    Table created.
    SQL> exec dbms_stats.set_table_stats( ownname=>'solarp', tabname=>'R1', numrows=> 100000000, numblks=>251342 ) ;
    PL/SQL procedure successfully completed.
    SQL> alter table r1 parallel 5 ;
    Table altered.
    SQL> set autotrace traceonly explain
    SQL> update r1 set status='XX' where created > ( sysdate - 7) ;
    0 rows updated.
    Execution Plan
    Plan hash value: 1840129185
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | TQ |IN-OUT| PQ Distrib |
    | 0 | UPDATE STATEMENT | | 5000K| 66M| 14083 (14)| 00:02:49 | | | |
    | 1 | UPDATE | R1 | | | | | | | |
    | 2 | PX COORDINATOR | | | | | | | | |
    | 3 | PX SEND QC (RANDOM)| :TQ10000 | 5000K| 66M| 14083 (14)| 00:02:49 | Q1,00 | P->S | QC (RAND) |
    | 4 | PX BLOCK ITERATOR | | 5000K| 66M| 14083 (14)| 00:02:49 | Q1,00 | PCWC | |
    |* 5 | TABLE ACCESS FULL| R1 | 5000K| 66M| 14083 (14)| 00:02:49 | Q1,00 | PCWP | |
    Predicate Information (identified by operation id):
    5 - filter("CREATED">SYSDATE@!-7)
    Thanks in advance

    The manuals get out of date and out of synch. Somewhere in the 9i manuals it says that there is "limited" support for all parallel DML. Your plan, as David said, is a parallel select with serial update - if you want to perform the update in parallel then you need an explicit:
    alter session enable parallel dml;Here's a plan (pulled from v$sql_plan in 10.2.0.3) for a similar update to yours. This plan is the parallel update version:
    update t1 set n1 = 0 where mod(id,100) = 0
    | Id  | Operation             | Name     | Rows  | Bytes | Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ Distrib |
    |   0 | UPDATE STATEMENT      |          |       |       |   753 (100)|          |        |      |            |
    |   1 |  PX COORDINATOR       |          |       |       |            |          |        |      |            |
    |   2 |   PX SEND QC (RANDOM) | :TQ10000 |   100 |   800 |   753   (0)| 00:00:10 |  Q1,00 | P->S | QC (RAND)  |
    |   3 |    UPDATE             | T1       |       |       |            |          |  Q1,00 | PCWP |            |
    |   4 |     PX BLOCK ITERATOR |          |   100 |   800 |   753   (0)| 00:00:10 |  Q1,00 | PCWC |            |
    |*  5 |      TABLE ACCESS FULL| T1       |   100 |   800 |   753   (0)| 00:00:10 |  Q1,00 | PCWP |            |
    Predicate Information (identified by operation id):
       5 - access(:Z>=:Z AND :Z<=:Z)
           filter(MOD("ID",100)=0)Note, particularly, that the UPDATE operation is the child of the PX SEND to coordinator. i.e. we update in the PX slaves, then tell the co-ordinator what we updated.
    Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    http://www.jlcomp.demon.co.uk

  • Query for updating prices if product IDs same

    I have a large Windows SQL 2000 database of products that
    need to have
    2007 prices.
    I have another Windows SQL 2000 database that has the correct
    prices
    that I can import into Windows SQL 2000 as a new table.
    I want to be able to UPDATE the Prices where product IDs
    match.
    What would an SQL query look like that would run in Query
    analyzer?
    So, basically, I need a query that would compare the product
    IDs and
    update the price column with the new price.
    Neither database is in the same location. One that holds the
    correct
    pricing is basically inaccessible to me. I can get a
    delimited file
    though. I know how to get that in.

    I've a table called Track, which has three columns named Part1, Part2 and Part3. I want all values of Part1 to be separated by a comma (,);
    No, don't go there.
    This breaks a fundamental point for relational databases: no repeating groups. A cell should hold an atomic value. And this is not only a matter of purism. Relational databases are designed from this principle, and breaking this means that you will need
    to write complex and higly inefficient code.
    The values in Part1 should be in a separate table, with one value per row.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Form on SQL query for updating.

    Hello again,
    Im trying to wirte a form to udapte the information in a table. I have a table with a PK which holds a persons name, and an activity assigned to them (and loads of other fields but they dont matter atm). I would like to have a form which has an SQL query running in one region and then the form underneath to be able to edit (reassign a person to a different activity) an item appearing in the query result. Ive got a form at the moment which is form on an sql query but its not updating when i fill out the form, is it something to do with the regions?
    http://img.photobucket.com/albums/v611/Funky_Monk/untitled.jpg
    So on the screenie, i have the bottom region for the query (no values in table hence the error (i think!))
    The call ID is FK to another table
    severity level and status will be usdated here
    description is self-explanitory
    analyst_id is the main field to be changed here, the call id will be assigned a new analyst via this form.
    action_id is actions carried out on this problem.
    Any help would be greatly appreciated.
    DM

    hi,
    Can you put this example on apex.oracle.com?
    Regards,
    Kartik Patel
    http://patelkartik.blogspot.com/
    http://apex.oracle.com/pls/apex/f?p=9904351712:1

  • [Solved partially] Sql query for updates compliance

    Hello
    I'm trying (with no success) to translate the "Software+Updates+-+A+Compliance%2fCompliance+1+-+Overall+compliance" report into a sql query that must run for a specific
    Software update group and for a specific Collection ID.
    The expected result should be like the report it self, I mean 3 lines with Kpi (pourcentage).
    The main query in this report is : 
    select
    CollectionID=@CollID,
    Status=sn.StateName,
    cs.NumberOfComputers,
    PComputers=convert(float, isnull(cs.NumberOfComputers, 0)*100.00) / isnull(nullif(cs.NumTotal, 0), 1),
    AuthListID=@AuthListID
    from (select CI_ID, NumTotal, [0]=NumUnknown, [1]=NumPresent+NumNotApplicable, [2]=NumMissing
    from fn_rbac_UpdateSummaryPerCollection(@UserSIDs)
    where CI_ID=@CI_ID and CollectionID=@CollID
    ) cnt
    unpivot (NumberOfComputers for [Status] in ([0], [1], [2])) cs
    left join fn_rbac_StateNames(@UserSIDs) sn on sn.TopicType=300 and sn.StateID=cs.Status
    where cs.NumberOfComputers>0
    order by cs.NumberOfComputers desc
    I have no clue on how to replace or use fr_rbac view when run outside a report.
    Can you please help me ?
    Thanks

    Hi,
    Glad to hear that and thank you for your sharing.
    Best Regards,
    Joyce
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Need help to write a query for Update statement with  join

    Hi there,
    The following update statement gives me error as the given table in set statement is invalid. But its the right table .
    Is the statement correct? Please help .
    update (
           select distinct(vpproadside.VEHICLE_CRED_OVERRIDE.vin)            
             from vpproadside.VEHICLE_CRED_OVERRIDE
             join vpproadside.vpp_vehicle
               on vpproadside.vpp_vehicle.vin = vpproadside.VEHICLE_CRED_OVERRIDE.vin
            where VPP_CARRIER_SEQ_NUMBER = 90
              and EXPIRY_DATE = '17-MAR-10'
       set vpproadside.VEHICLE_CRED_OVERRIDE.EXPIRY_DATE = '15-SEP-10';Edited by: Indhu Ram on Mar 12, 2010 1:00 PM
    Edited by: Indhu Ram on Mar 12, 2010 1:22 PM
    Edited by: Indhu Ram on Mar 12, 2010 2:35 PM
    Edited by: Indhu Ram on Mar 15, 2010 8:04 AM
    Edited by: Indhu Ram on Mar 15, 2010 8:06 AM
    Edited by: Indhu Ram on Mar 15, 2010 8:28 AM

    Ask Tom has very good discussion about this, if UPDATE does not work for PK issue, you can use MERGE
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:760068400346785797

  • Query for updating the records

    I have the two tables....
    CREATE TABLE temp_1
    ( ST_NM VARCHAR2(30),STATUS_ID VARCHAR2(1) NOT NULL ENABLE,ST_ID VARCHAR2(20) primary key,REJ_USER_NM varchar2(10))
    sample Data :
    insert into temp_1 values('S010054','R','ST9749109','TEST_1');
    insert into temp_1 values('S010179','R','ST9749147','');
    insert into temp_1 values('S010582','N','ST9749258','');
    CREATE TABLE temp_2
    ( REJ_USER_NM VARCHAR2(20),ST_NM VARCHAR2(30),
    STATUS_ID VARCHAR2(1) NOT NULL ENABLE,ST_ID VARCHAR2(20))
    sample data:
    insert into temp_2 values('','S010054','N','ST9749109');
    insert into temp_2 values('','S010054','N','ST9749109');
    insert into temp_2 values('TEST_1','S010054','N','ST9749109'');
    insert into temp_2 values('','S010054','I','ST9749109');
    insert into temp_2 values('','S010179','N','ST9749147');
    insert into temp_2 values('TEST_2','S010179','N','ST9749147');
    insert into temp_2 values('','S010179','N','ST9749147');
    insert into temp_2 values('','S010179','N','ST9749147')
    insert into temp_2 values('TEST_5','S010582','R','ST9749258');
    insert into temp_2 values('TEST_5','S010582','N','ST9749258');
    insert into temp_2 values('','S010582','N','ST9749258');
    insert into temp_2 values('','S010582','N','ST9749258')
    I want the UPDATE query based on below conditions to update the REJ_USER_NM in temp_1 table.
    From temp_1 table ,STATUS_ID is 'R' and REJ_USER_NM is null and compare the set_id column value
    with the temp_2 table,where REJ_USER_NM is not null and status id is 'N'. REJ_USER_NM column from
    temp_2 table need to be update in the REJ_USER_NM column of temp_1 table.
    After completion of updation,output is in below format; if i run below qry
    ====================================
    select * from temp_1;
    {S010054},{R},{ST9749109},{TEST_1}
    {S010179},{R},{ST9749147},{TEST_2}
    {S010582},{N},{ST9749258},{}
    ======================
    Edited by: 849971 on May 2, 2011 8:25 PM

    Why is that the row
    {S010582},{N},{ST9749258},{}
    is not updated to TEST_5 ?? Based on your rules and data. it must be updated to test_5. Are you missng any rules?
    Try some thing like,
    UPDATE temp_1
       SET REJ_USER_NM  =
              (SELECT REJ_USER_NM
                 FROM temp_2
                WHERE     status_id = 'N'
                      AND temp_1.st_id = temp_2.st_id
                      AND temp_2.REJ_USER_NM IS NOT NULL)

  • Need Query for Update

    CREATE TABLE TEST_MATCH
    MTCH1 NUMBER(9),
    MTCH2 NUMBER(9),
    UPDT_MTCH CHAR(2 BYTE),
    UPDT_NBR NUMBER(10)
    SET DEFINE OFF;
    Insert into TEST_MATCH
    (MTCH1, MTCH2, UPDT_MTCH)
    Values
    (2616131, 300137070, '02');
    Insert into TEST_MATCH
    (MTCH1, MTCH2, UPDT_MTCH)
    Values
    (2571056, 300129277, '02');
    Insert into TEST_MATCH
    (MTCH1, MTCH2)
    Values
    (2623529, 300175046);
    COMMIT;
    i need to update the column UPDT_NBR which is currently NULL
    UPDATE TEST_MATCH
    SET UPDT_NBR =
    NVL(2616131, 300137070) FOR THESE TWO MATCHES-> (1234567),
    (2571056, 300129277) FOR THESE TWO MATCHES -> (1111111),
    (2623529, 300175046) FOR THESE TWO MATCHES ->(222222);
    Thanks for all your help in my previous post. And thanks again for looking into my post.

    Hi,
    If it is just three records it would be better if you fire individual update statement 3 times.
    But if it is a sample data only and you have many updates to do then only way I think it is is possible is either by creating temporary table or using subfactoring(same as creating temporary table)
    Regards
    Anurag

  • SQL query for updating values in same cell of a table

    Hi All,
    I'm stuck with a problem and it stands as follows:
    Table name: Track
    Part1  Part2  Part3
    NULL   NULL   NULL
    I've a table called Track, which has three columns named Part1, Part2 and Part3. I want all values of Part1 to be separated by a comma (,); it should not be overwritten, neither they should appear in separate row, in fact they should look like this:
    Part1    Part2    Part3
    1,2,3    5          SUBM1
    The new values of Part1 should appear in next row only when value of Part3 changes, so if Part3 changes from SUBM1 to SUBM2, it should look like this:
    Part1    Part2    Part3
    1,2,3    5          SUBM1
    1,2,3    5          SUBM2
    Count of values in Part1 never exceeds the value of Part2, so if Part2 is 5, then Part1 will look like 1,2,3,4,5. So in other words loop will run only up to the value of Part2.
    Please advise how this could be achieved?
    Kind regards,
    Aniruddha Jagdale

    I've a table called Track, which has three columns named Part1, Part2 and Part3. I want all values of Part1 to be separated by a comma (,);
    No, don't go there.
    This breaks a fundamental point for relational databases: no repeating groups. A cell should hold an atomic value. And this is not only a matter of purism. Relational databases are designed from this principle, and breaking this means that you will need
    to write complex and higly inefficient code.
    The values in Part1 should be in a separate table, with one value per row.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Query for update

    . I have a table with a column city. The values are delhi and banglore. I need to update banglore with delhi and delhi with Banglore

    shiv kumar wrote:
    . I have a table with a column city. The values are delhi and banglore. I need to update banglore with delhi and delhi with Banglore
    update <table> set city = 'X' where city = 'banglore'
    update <table> set city = 'banglore' where city = 'delhi'
    update <table> set city = 'delhi' where city = 'X'
    /

  • For Update Query

    Hi All,
    I having block level 8000 records, I Scroll down from First record to last record it is takeing more time.
    I Observed tkproof while scrolling two select statments are running..
    1) pre-query block level
    2) For update query
    For update query -> How is is forming? Any Property or some else?
    I am not able to find the second query..where it is forming..How to restrict the second query.
    Query Array size - 10
    Number of records buffered - 10
    Number of records Displayed - 10
    Query all records - No
    Locking mode - Immediate
    Key mode - Automatic
    Version - Oracle 10g
    Plz ........any

    The for update -query is generaetd by forms when its locking the record. If you didn't change anything in the record "by hand", check if there is some code in the POST-QUERY-trigger which forces the record to be locked. if its the POST-QUERY you can issue the following command to avoid the lock at the end of the POST-QUERY:
    SET_RECORD_PROPERTY(:SYSTEM.TRIGGER_BLOCK, :SYSTEM.TRIGGER_RECORD, STATUS, QUERY_STATUS);

  • What is the query to update table in ejb3.0

    Hi Friends,
    I am developing one application using ejb3.0 in Netbeans IDE 6.7.1 with Glassfish Application server.
    To insert data we use "entitymanager.persist(Insert insert);"
    To retrieve all data from table "entitymanager.createQuery("")'
    In the same way what is the query for update?
    Could you please help me.
    Thanks in advance.

    [the answer|http://lmgtfy.com/?q=java+jpa+udpate+query]

  • For Update Query with Wait Clause from ORACLE Forms

    Hi
    We are using Oracle Forms 10g running with 10g database 10.2.0.1.0. We happend to see a query which is getting generated in AWR report like Select rowid, all_columns from TableName for Update of C1 Nowait. But no such query is really written in forms and we are aware that, Any query prefixed with rowid is definitely executing from Forms. But how the ForUpdate and Nowait clause is appended to the query.
    We have checked the following properties in the database Block
    *1) Locking Mode is set to Automatic*
    *2) Update Changed Columns only is set to YES*
    *3) Query all records is set to No (Though this particular property may not be relevant to the issue)*
    What is the property or setting which might trigger such a query from ORACLE Forms with ForUpdate and Nowait clause.
    Any ideas/suggestions on why such behaviour. Please have a healthy discussion on this. Thanks in advance.

    Why have you started another thread on the same thing?
    FOR UPDATE cursor is causing Blocking/ Dead Locking issues
    Just use one thread to avoid confusion.
    The fact that nobody has answered on the other thread for a couple of days could be to do with it being the weekend and most people are not at work.
    Either be patient or, if it's more "urgent" than that, raise a SR/Tar with Oracle metalink.

  • For Update Nowait Query Generated Implicitly by Forms

    Recently we had a problem in one form because of a query getting generated implicitly by Forms with for update and nowait clause. i.e.
    Select Col1, Col2, Col3 Where Rowid= :1 for update of Col1 NoWait if we change the sequence of the Fields in block by shuffling the Fields i.e Bringing Col 1 to Col3 and Col3 to Col1 the query formed is some thing like this i.e.
    Select Col3, Col2, Col1 Where Rowid= :1 for update of Col3 NoWait  We just want to know when this query is getting fired and how i.e. Upon firing of which trigger in Forms this is getting fired in the DB. Because we are for sure we are not firing this query either from front end or back end. We are not locking the block any where or changing the lock mode of the block programatically.
    Few block level properties relevant to this
    Locking Mode - Automatic
    Update Changed Columns Only - Yes
    Possible reasons which we feel is that when we are assigning the values to a field programattically and when more than 1 user is navigating on the same block this may happen. Because Forms doesnt knows whether the user has edited the record manually or programatically. But we have noticed this query runs even when only 1 user is connected to this schema. This is our understanding so far any ideas/suggestions to avoid this or overcome this is appreciated.
    Thanks in advance

    Locking Mode - Automatic or Immediate, means select for update is issued as soon as value in a base table item changed by user or programmatically.
    Setting it to "Delayed" will delay lock until commit-time.
    You can override this behavior by creating ON-LOCK triger.

Maybe you are looking for

  • Cannot End Call on Q10 after upgrading to OS 10.2

    I cannot End Call (mostly Outgoing) after upgrading to OS 10.2. The receivers phone keeps ringing even after i try to disconnect the call. The "END CALL" option is grayed out and the red led on the top left keeps blinking. This happens very frequentl

  • Iphoto-iphone sync weirdness after upgrading to Mavericks

    I didn't receive any replies on the Mavericks board, so I'll repost this here.  Really puzzled and annoyed. recently upgraded my iMac to Mavericks from Snow Leopard (early adopter that I am).  Much has gone more smoothly than I expected. However, one

  • MBP screen black after using DVI to HDMI cable

    Over a week ago I attempted to connect my MBP 2007 model to my samsung television with HDMI in. I have used this cable before but always have trouble getting it to work with this TV and my computer. Well, I plugged it in and the screen on my computer

  • Transfer music from iphone 4gs to new macbook pro

    Hi, I need assistance on how to transfer music from my iphone 4gs to my new macbook pro.  My previous macbook pro was damaged and I can't get the music from the old macbook as the hard drive is severly damaged. I dont want to loose my music, so any h

  • Chipmunk audio in classic

    quicktime version currently is 7.04, have not updated to 7.1 yet and in classic it is 6.5. Running any classic apps causes the audio to be sped up and it is impossible to make any of it out. starting up the classic version of qt and manually having i