Is this update query is possible

update b set b.[NetSales] = b.[NetSales] - sum(a.[Amount Including VAT]) from [Sales_Cube_Source].[dbo].[Sales Cr_Memo Line] as a 
join [FactNetSales_Salesperson1] as b on a.[Sell-to Customer No_] collate SQL_Latin1_General_CP1_CI_AS=b.[Customer]
join [Sales_Cube_Source].[dbo].[Item] as c on b.[Division]=c.[Global Dimension 1 Code]
group by a.[Sell-to Customer No_]

it should be this
update b
set b.[NetSales] = b.[NetSales] - a.TotalVATAmount
from (
select [Sell-to Customer No_] ,
sum([Amount Including VAT]) AS TotalVATAmount
FROM [Sales_Cube_Source].[dbo].[Sales Cr_Memo Line]
GROUP BY [Sell-to Customer No_]
)as a
join [FactNetSales_Salesperson1] as b
on a.[Sell-to Customer No_] collate SQL_Latin1_General_CP1_CI_AS=b.[Customer]
join [Sales_Cube_Source].[dbo].[Item] as c on b.[Division]=c.[Global Dimension 1 Code]
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

Similar Messages

  • Is there any way we can simplify this update query ?

    is there any way we can simplify this update query ? There is nothing wrong with the query ,but it looks so clumsy ...is there any other ways of doing this update  like using with clause  or exists or any other?
    [code]
    UPDATE STG_TMP_MBS_POOL s             SET s.instrument_id =             case  when  (                                     (select distinct iai.alternate_id  from                             instrument_alternate_id iai, STG_TMP_MBS_POOL s       where s.fi_instrument_id=iai.fi_instrument_id                             and  iai.alternate_id_type_code  IN (       'FMR_CUSIP','CUSIP'))  > 1)       then                             (select distinct iai.alternate_id from                             instrument_alternate_id iai, STG_TMP_MBS_POOL s       where s.fi_instrument_id=iai.fi_instrument_id                             and  iai.alternate_id_type_code =  'FMR_CUSIP')             else (select distinct iai.alternate_id from                             instrument_alternate_id iai, STG_TMP_MBS_POOL s       where s.fi_instrument_id=iai.fi_instrument_id                             and  iai.alternate_id_type_code IN ('FMR_CUSIP',       'CUSIP'))       END;
    [\code]

    update stg_tmp_mbs_pool s
       set s.instrument_id = case when (select distinct iai.alternate_id
                                          from instrument_alternate_id iai,
                                               stg_tmp_mbs_pool s
                                         where s.fi_instrument_id = iai.fi_instrument_id
                                           and iai.alternate_id_type_code in ('FMR_CUSIP','CUSIP')
                                       ) > 1
                                  then (select distinct iai.alternate_id
                                          from instrument_alternate_id iai,
                                               stg_tmp_mbs_pool s
                                         where s.fi_instrument_id = iai.fi_instrument_id
                                           and iai.alternate_id_type_code = 'FMR_CUSIP'
                                  else (select distinct iai.alternate_id
                                          from instrument_alternate_id iai,
                                               stg_tmp_mbs_pool s
                                         where s.fi_instrument_id = iai.fi_instrument_id
                                           and iai.alternate_id_type_code in ('FMR_CUSIP','CUSIP')
                             end
    Maybe
    begin
    update stg_tmp_mbs_pool s
       set s.instrument_id = (select distinct iai.alternate_id
                                from instrument_alternate_id iai,
                                     stg_tmp_mbs_pool s
                               where s.fi_instrument_id = iai.fi_instrument_id
                                 and iai.alternate_id_type_code in ('FMR_CUSIP','CUSIP')
    update stg_tmp_mbs_pool s
       set s.instrument_id = (select distinct iai.alternate_id
                                from instrument_alternate_id iai,
                                     stg_tmp_mbs_pool s
                               where s.fi_instrument_id = iai.fi_instrument_id
                                 and iai.alternate_id_type_code = 'FMR_CUSIP'
    where s.instrument_id > 1;
    end;
    Regards
    Etbin

  • Can we improve further this update query

    Can we optimize the following query further.
    UPDATE OPTPRC_CHANGES_PK
    SET UPDATEFLAG_ = 'X'
    WHERE (UPDATEFLAG_ = 'U' OR UPDATEFLAG_ = 'A')
    AND EXISTS
    ( SELECT 1 FROM OPTPRC
    WHERE OPTPRC.DATE_ = OPTPRC_CHANGES_PK.DATE_
    AND OPTPRC.EXCHCODE = OPTPRC_CHANGES_PK.EXCHCODE
    AND OPTPRC.CONTRCODE = OPTPRC_CHANGES_PK.CONTRCODE )
    The OPTPRC table contains about 10 million rows and OPTPRC_CHANGES_PK table contains about 1.5 million rows. The query takes about 20 minutes to complete. Ouch.
    The index (Date_,Exchcode,contrcode) is in place on both tables.
    Query Plan_
    According to query plan, it is not using any indexes. Hash semi join is being used and table are fully scanned.
    Oracle 10g is being used on Solaris 10.
    Can we improve this query.

    Following is th query plan for the query poposed by SeánMacGC
    Query Plan
    PLAN_TABLE_OUTPUT
    Plan hash value: 72452462
    | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (
    | 0 | UPDATE STATEMENT | | 1558K| 53M| | 29378
    | 1 | UPDATE | OPTPRC_CHANGES_PK | | | |
    |* 2 | HASH JOIN | | 1558K| 53M| 44M| 29378
    |* 3 | TABLE ACCESS FULL| OPTPRC_CHANGES_PK | 1521K| 27M| | 2137
    | 4 | TABLE ACCESS FULL| OPTPRC | 9968K| 161M| | 11182
    Predicate Information (identified by operation id):
    2 - access("OPTPRC"."DATE_"="OPTPRC_CHANGES_PK"."DATE_" AND
    "OPTPRC"."EXCHCODE"="OPTPRC_CHANGES_PK"."EXCHCODE" AND
    "OPTPRC"."CONTRCODE"="OPTPRC_CHANGES_PK"."CONTRCODE")
    3 - filter("OPTPRC_CHANGES_PK"."UPDATEFLAG_"='A' OR
    "OPTPRC_CHANGES_PK"."UPDATEFLAG_"='U')

  • Cannot convert msaccess update query to view

    Hello,
    I am trying to migrate an msaccess database to oracle using oracle sql developer. The problem is that I get error messages when I convert the captured access model to an oracle model.
    I only get error messages on the converted views. These are originally update queries in access like the following example:
    UPDATE [Tbl Zuguebersicht CMA] INNER JOIN 1_PrioTab ON [Tbl Zuguebersicht CMA].Zugnummer = [1_PrioTab].ZugNr SET [Tbl Zuguebersicht CMA].Prioritaet = [1_PrioTab]![InternePrio];
    In the captured model this query is already listed under the node for views. When I convert the model, I get the error message that it cannot be converted.
    If I got it right, an update query cannot be converted to a view, is that correct? So it should rather be a function. I couldn't find a possibility to change this!
    Or am I on the wrong track and there is just a special problem with exactly this update query? But then again, all the update queries could not be converted!
    Help would greatly be appreciated! Thanks in advance...
    Edited by: user8772417 on Sep 17, 2009 8:54 AM

    Thanks for your answers!
    Well I guess then I I have to create the stored procedures myself after the conversion and delete the useless views. That shouldn't be a big deal! I only wanted to avoid searching for the code lines where the stored procedure has to be called - therefore, the automatic way would have been much more comfortable :-)
    I will request this feature on the sql developer page. I can't imagine I am the only one facing this particular MS Access conversion problem.
    Thanks again,
    Max

  • Update query is not working (ora-01427)

    RDBMS 10gr2
    Long story short, I created a column from one table in another because the table it was moved from isn't really needed as all the other information is stored in other tables. With that the original column has values that need to be copied to the new column before the old table is dropped.
    I'm using this update query:
    update bi_req bir
       set bir.job_name =
            (select distinct bij.job_name
               from bi_jobs bij,
                    bi_freq bif,
                    bi_apps bia,
                    bi_req  bir
              where bij.fk_bi_req_id = bir.pk_bi_req_id
                and bia.pk_bi_apps_id = bij.fk_bi_apps_id
                and bif.pk_bi_freq_id = bij.fk_bi_freq_id)
    where bir.job_name is null;If I run the select statement separately, I get the exact results I need however whenever I run the entire statement, I get:
    Error: ORA-01427: single-row subquery returns more than one row

    I removed the extra bi_req from the subquery and that didn't help any.
    If I replace the '=' with IN (also ALL) I get the error message:
    ORA-00927: missing equal signHere is the create table for the table that will soon be dropped:
    CREATE TABLE BI_JOBS
      PK_BI_JOBS_ID  NUMBER                         NOT NULL,
      FK_BI_APPS_ID  NUMBER                         NOT NULL,
      FK_BI_FREQ_ID  NUMBER                         NOT NULL,
      JOB_NAME       VARCHAR2(50 CHAR)              NOT NULL,
      FK_BI_REQ_ID   NUMBER                         NOT NULL
    )and the relevant columns for the table that has the column that needs the values from bi_jobs.job_name
    CREATE TABLE BI_REQ
      PK_BI_REQ_ID   NUMBER                         NOT NULL,
      FK_FREQ_ID     NUMBER                         NOT NULL,
      FK_BI_APPS_ID  NUMBER,
      JOB_NAME       VARCHAR2(50 CHAR)
    )Whatever value that is in bi_jobs.job_name I want in bi_req.job_name assuming that bi_jobs.fk_bi_req_id equals bi_req.pk_bi_req_id

  • Help in Update Query

    Hi, I want to update status_code of table_2. T_ID is the primary key in both table (Table_1 and table_2). The condition is any person's age >70 then status_code should be 'R' and if person's age<70 then status_code should be 'N'. Please help on this
    Update query.
    /*Table_1*/
    T_ID  LASTNAME  FIRSTNAME   DOB
    1001 KAISER      SUJIR    01/01/1942
    1002 SMITH     HUJR       01/01/1948
    1003 JOHN      JANE       02/01/1958
    /*Table_2*/
    T_ID  LASTNAME  FIRSTNAME   STATUS_CODE
    1001 KAISER      SUJIR    R
    1002 SMITH     HUJR       R
    1003 JOHN      JANE        R
    /*Need the Following Result after the Update*/
    T_ID  LASTNAME  FIRSTNAME   STATUS_CODE
    1001 KAISER      SUJIR    R   --The Age is >70 that's why status_code is 'R'
    1002 SMITH     HUJR       N  --The Age is <70
    1003 JOHN      JANE        N  --The Age is <70

    DECLARE @table1 TABLE (T_ID INT, lastName VARCHAR(30), firstName VARCHAR(30), dob DATE)
    INSERT INTO @table1 (T_ID, lastName, firstName, dob) VALUES (1001, 'KAISER', 'SUJIR' ,'01/01/1942'),(1002, 'SMITH', 'HUJR', '01/01/1948'),(1003, 'JOHN', 'JANE', '02/01/1958'),(1004, 'Jack', 'Jackson', '12/03/1944')
    DECLARE @table2 TABLE (T_ID INT, lastName VARCHAR(30), firstName VARCHAR(30), statusCode CHAR(1))
    INSERT INTO @table2 (T_ID, lastName, firstName, statusCode) VALUES (1001, 'KAISER', 'SUJIR', 'R'),(1002, 'SMITH', 'HUJR', 'R'),(1003, 'JOHN', 'JANE', 'R'),(1004, 'Jack', 'Jackson', 'R')
    -- tables set up
    UPDATE @table2
    SET statusCode = CASE WHEN DATEDIFF(YEAR,t1.dob,CURRENT_TIMESTAMP) - CASE WHEN DATEADD(YEAR,DATEDIFF(YEAR,t1.dob,CURRENT_TIMESTAMP),t1.dob) > CURRENT_TIMESTAMP THEN 1 ELSE 0 END >= 70 THEN 'R' ELSE 'N' END
    FROM @table2 t2
    INNER JOIN @table1 t1
    ON t2.T_ID = t1.T_ID
    SELECT *, DATEDIFF(YEAR,t1.dob,CURRENT_TIMESTAMP) - CASE WHEN DATEADD(YEAR,DATEDIFF(YEAR,t1.dob,CURRENT_TIMESTAMP),t1.dob) > CURRENT_TIMESTAMP THEN 1 ELSE 0 END
    FROM @table2 t2
    INNER JOIN @table1 t1
    ON t2.T_ID = t1.T_ID

  • Error in update query with join

    hi all,
    im using oracle 10g in windows.
    im not able to use this update query having join......
    UPDATE
    b
    SET
    b.is_stud = 1
    FROM
    boy b
    INNER JOIN
    relationship r
    ON
    b.id = r.boy_id;
    thanks a lot..................

    887268 wrote:
    hi, thanks,,,,,,,,,
    create table emp ( id,name,date,empno);
    create table emp_status(slno,ename,empno);
    i need to update "emp.name" in "emp" table from "emp_status.ename"
    where emp.empno=emp_status.empno;
    i.e) for all matched "empno" from both table, update "emp.name" from "emp_status.ename"Whats the relationship between emp and emp_status tables? If there exists one to one mapping for empno in both tables, then try
    update emp e
    set    e.name = (select es.ename
                     from   emp_status es
                     where  e.empno = es.empno)

  • Update Query based on a reference to another table

    I have a table TableA which contains two columns PKey, EmployeeID.
    I have anohter table TableB which contains FName, LName, City, State and a reference key TableA_PKey referenced to PKey in TableA.
    I want to update TableB and set the values of TableB.State = 'CA' where TableA.EmployeeID in (111, 222, 333)
    How do I write this update query? thanks

    Hi,
    This does what you requested:
    UPDATE  tableb
    SET     state     = 'CA'
    WHERE     tablea_pkey  IN (
                            SELECT  pkey
                       FROM    tablea
                       WHERE   employeeid     IN (111, 222, 333)
    ;Whenever you have a problem, it helps if you post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables, and the results you want from that data.
    In the case of DML problems (including UPDATE), the sample data should show what all the tables are like before the DML, and the results will be the contents of the changed table after the DML.
    Always say what version of Oracle you're using.

  • Unanle to run update query

    Hi Experts,
    I got the solution from SAP to run update query on table E071 by using SQLPLUS prompt.
    But when I run this query I am getting message as below:
    ERROR at line 1:
    ORA-00942: table or view does not exist
    I am also unable to execute simple query like
    - select * from E071;
    - desc E071;
    For all above queries I am getting the same message as shown.
    But I am able to open view the table in SE11.
    I am also able to execute the following query in sqlplus -
    - select owner, table_name from all_tab_cols where table_name like 'E071';
    - select * from all_tables where table_name like 'E071';
    Please provide me the solution / alternative to run this update query on table E071.
    Thanks in Advance
    Best RG//
    Ramesh.

    Hi,
    if you use
    sqlplus / as sysdba
    you are SYS to the DB. You need to specify the schemauser.
    desc sapr3.E071
    desc sapsr3.E071
    desc sapsid.E071
    depending on how you schemauser is named.
    check your sidadm environment:
    env | grep -i schema
    Hope this helps
    Volker

  • Using nested IIF expressions in an update query - is it possible?

    Hi everyone,
    I've been tasked by my manager to build a database which replicates a large, complicated Excel spreadsheet that consumes too much of our team's time and system resources. I've just about got most of it, but there is one particular required field that, in
    Excel, requires multi-layered nested If/Then formulae. I have to ask if building something similar in Access is possible. Here is the problem and the logic:
    Let us assume two established fields, Field 1 and Field 2; and then one field to be created via Update query, Field 3.
    Let us further assume that in Fields 1 and 2, there are three specific alphanumeric sequences occurring (“X1A”, “X1”, and “Z1”) that need to be identified and then called out as either “S1” or “U1” in field 3.
    If an Update Query were to be written to populate Field 3 with either “S1” or “U1” depending on one of the three alphanumeric sequences appearing in either Field 1 or Field 2, could it be written as the following expression, using the IIF and OR operators?
    And if so, is the syntax of the following expression correct?
    IIf([FIELD 1]="* X1A", "U1", OR IIf([FIELD 2]="* X1", "U1", OR IIf([FIELD 2]="* Z1", "U1", OR IIf([FIELD 1]="* X1", "U1", OR IIf([FIELD 1]="* Z1", "U1", "S1")))))
    Any help, critiques, or guidance would be appreciated.

    IMHO, a main consideration when "migrating" from Excel to Access is that a relational database is fundamentally different from a spreadsheet (although there can be much overlap).  In Excel, calculated values are "live" (unless you paste the values only
    into some other cells).  To replicate this "live" quality in Access, you can use a query with a calculation to display (not create or update) Field 3 in your case; Field 3 really wouldn't be a field, just a representation (query, form, report) or snapshot
    (export, print).  One reason for this is to avoid conflicts and redundancy.  In other words, if Field 3 is based solely on Fields 1 & 2 and some rule, then usually there is no need to waste disk space to store Field 3 and you don't risk Field
    3 being wrong as in the case when the rule changes.
    So here are a couple of options.
    1) Create view only query to display Field 3.  In query design view, enter the following where you would normally select a field:
    [FIELD 3]: IIf([FIELD 1]="* X1A", "U1", IIf([FIELD 2]="* X1", "U1", IIf([FIELD 2]="* Z1", "U1", IIf([FIELD 1]="* X1", "U1", IIf([FIELD 1]="* Z1", "U1", "S1")))))
    I assume you literally mean the asterisk character and are not trying to invoke a wildcard for the LIKE operator.
    There are other ways of doing this (e.g. with the LIKE operator or multiple queries and UNION), but I leave that up to you to explore.
    2) Actually update the value of FIELD 3 in a table.  Create two update queries and use your rules as conditions (i.e. the criteria in the bottom of query design).
    a) Update query 1 (run first): set [FIELD 3] = "U1" where [FIELD 1] = "* X1A" OR [FIELD 1] = "* X1" OR [FIELD 1] = "* Z1" OR [FIELD 2] = "* X1" OR [FIELD 2] = "* Z1"
    b) Update query 2 (run after): set [FIELD 3] = "S1" where [FIELD 3] is null
    Again, there are other ways of doing this such as setting the default value of [FIELD 3] in the table to "S1" and just running update query 1.
    Good luck.

  • I have problem with account that i can't make update or buy from app store There is massage appear in my payment page that i must contact with i tunes support to complete this transaction Please help me to fixe this problem as soon possible Hany hassan 00

    I have problem with account that i can't make update or buy from app store
    There is massage appear in my payment page that i must contact with i tunes support to complete this transaction
    Please help me to fixe this problem as soon possible
    Hany hassan
    0096597617317
    0096596677186
    Thank you

    You need to Contact iTunes Support...
    Apple  Support  iTunes Store  Contact Us

  • IPhoto update can't be installed on my MAC ref. "This update is not available for this Apple ID either because it was bought by a different user or the item was refunded or cancelled." this is not possible help?

    Recent upgrade to OS X Yosemite on my MAC and iPhoto update can not  now be installed msg reads, "This update is not available for this Apple ID either because it was bought by a different user or the item was refunded or cancelled." this is not possible help?

    That error message can be misleading. It means, that iPhoto on your Mac is not associated with your Apple ID.
    Either you did not set up  your Mac using the same Apple ID - did someone help with your setup and use a different ID? Perhaps a family member? Or did you let someone borrow your installer disks?
    Or did you not yet "Accept" iPhoto and other iLife apps to your Apple ID? Check the "Purchased" tab of the App Store, if any applications are waiting to be accepted. If you see "Accept" buttons, press them.
    You may  be unable to "Accept" now, if you missed the update to iphoto 9.5.1 on Mavericks. You could try to buy iPhoto, however. If you are lucky, it may show for free.
    Backup your iPhoto library, if you do not have a current backup.
    Uninstall iPhoto by deleting it from the Applications folder, but do not empty the Trash, so you can put it back,if need be.
    Launch the App Store, click the "Store" menu, and sign in with your current AppleID.
    Open the main page "Featured" of the App Store and search for iPhoto.
    If iPhoto is listed as "Free", click the "Free" button to buy it with your current AppleID.
    If it is not showing as free, there is no help but contacting the App Store Support to sort out the AppleID. Use this link: http://www.apple.com/support/mac/app-store/contact/

  • I have upgraded my computer to program the MAC OS X but would like to remove this update and revert to the old one. Is this possible and how do I proceed?

    I have upgraded my computer to program the MAC OS X but would like to remove this update and revert to the old one. Is this possible and how do I proceed?

    Not easily, unless you backed up your data.
    Did you?  If not, let that be a lesson to never install anything without a backup:
    https://discussions.apple.com/docs/DOC-1992
    https://discussions.apple.com/docs/DOC-1948

  • Anytime I open Firefox I get the follopwing meesage: It is storngly recommended that you appl this update as soon as possible. When I trr to di it, it is showing that it is trying to connect to the update server but nothing is happening

    Anytime I open Firefox I get the following message: It is strongly recommended that you apply this update as soon as possible. When I try to do it, it is showing that it is trying to connect to the update server but nothing is happening

    If there are problems with updating then best is to download the full version and uninstall the currently installed version.
    Download a fresh Firefox copy and save the file to the desktop.
    * Firefox 7.0.x: http://www.mozilla.com/en-US/firefox/all.html
    * Uninstall your current Firefox version.
    * Do not remove personal data when you uninstall the current version or you lose your bookmarks and other data in the profile folder.
    Remove the Firefox program folder before installing that newly downloaded copy of the Firefox installer.
    * 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.
    Your bookmarks and other profile data are stored elsewhere in the Firefox Profile Folder and won't be affected by a reinstall, but make sure that you do not select to remove personal data if you uninstall Firefox.
    * http://kb.mozillazine.org/Profile_folder_-_Firefox
    * http://kb.mozillazine.org/Profile_backup

  • Each time I open Firefox, I get a popup window that says "It is strongly recommended that you apply this update for Firefox as soon as possible." But I have updated Firefox.

    But I have updated Firefox. And if I tell it to do the update, it runs and runs and runs but nothing ever happens. It has a 'view more information about this update' link but the link does not work.

    According to your user agent string you are not using the latest version of Firefox. It shows you have version 4.0, the latest version is 4.0.1
    In the Help menu select "About Firefox", this should check for updates and then let you install the latest version.
    If that does not work, try downloading the latest version from http://www.mozilla.com/ then installing it over your current version.

Maybe you are looking for