2 sql statements in one trigger?

Greetings,
I am working with the Oracle 10g Database. While creating several triggers I am encountering quite some problems. In fact, I want to do 2 steps in one trigger. Is that possible? e.g:
Before Update on table for each row
begin
Update table set column=Max(column)+1 where column = 0 and ID = :old.ID;
then
Insert into table values (column1, column2, column3, column)
values (:new.column1, :new.column2, :new.column3, :new.column)
end;
What I want to do is that before an update on the table
1st: update current row and set one value to the max of the column + 1
2nd: insert the new values which are given by the original update statement with the value for the column = 0, which indicates later that this row is the newest one.
Is that somehow possible? I just read that normally you only have one DML statement per trigger. The problem is that both update and insert statement need to be triggered at the same time everytime someone tries to update values of the current table.
best regards
Jörn

> The problem is that I have more than 30 tables with
history, creating a history table for each would be
very bad...
Why is it bad to have 30 history tables? I currently work with an application having 141 history tables. Nothing bad about it over here.
> And lets say i am not the man who first intended this
structure, i am just the one who has to build up the
database as told ;-) So the history should be zero
for the latest version.
We are just saying that your current implementation isn't the best one out there for storing history. As said, you would have to circumvent the mutating table problem. And you would have to take special care about the multi-user situation where two sessions are updating/inserting at the same time and you wouldn't want both to use the same max(column)+1.
Using a history table is an alternative, and so is introducing a "creation_date" column and selecting the rows with the max(creation_date) as your current row.
Regards,
Rob.

Similar Messages

  • Multiple Oracle SQL statements in one Add Command

    I am creating a report that needs a bunch of processing(SQL DDL statements) before the final select statement is generated for the report.
    I am connecting to Oracle database however Crystal Report only allows me to give one SQL statement in one Add Command.
    Is there a way to give multiple statements in one "Add Command" for the report ?
    Thanks.

    you can add more than one "Add Command" in the same report, and you can also treat them as views or table, so you can link them to each others and so on
    good luck

  • Does Java support mutliple sql statements in one call?

    statment.executeUpdate("DROP DATABASE IF EXISTS diy55;CREATE DATABASE IF NOT EXISTS diy55 DEFAULT CHARACTER SET utf8;GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER,INDEX,USAGE on diy55.* TO 'diy55'@'localhost' identified by 'diy55';FLUSH PRIVILEGES;");Java seemes doesn't support multiple sql statements in one call, just like PHP mysql_query(), is it?

    Then just extend the java.sql.Statement to your own Statement class and write logic which splits the given query at the right places and executes them one by one.
    That the mysql_query() already has it built-in wouldn't say that it isn't possible in Java. Comparing with PHP is a bit pointless, it is a completely different language.

  • Need help on how to code this SQL statement! (one key has leading zeros)

    Good day, everyone!
    First of all, I apologize if this isn't the best forum.  I thought of putting it in the SAP Oracle database forum, but the messages there seemed to be geared outside of ABAP SELECTs and programming.  Here's my question:
    I would like to join the tables FMIFIIT and AUFK.  The INNER JOIN will be done between FMIFIIT's MEASURE (Funded Program) field, which is char(24), and AUFK's AUFNR (Order Number) field, which is char(12).
    The problem I'm having is this:  All of the values in AUFNR are preceeded by two zeros.  For example, if I have a MEASURE value of '5200000017', the corresponding value in AUFNR is '005200000017'.  Because I have my SQL statement coded to just match the two fields, I obviously get no records returned because, I assume, of those leading zeros.
    Unfortunately, I don't have a lot of experience coding SQL, so I'm not sure how to resolve this.
    Please help!  As always, I will award points to ALL helpful responses!
    Thanks!!
    Dave

    >
    Dave Packard wrote:
    > Good day, everyone!
    > I would like to join the tables FMIFIIT and AUFK.  The INNER JOIN will be done between FMIFIIT's MEASURE (Funded Program) field, which is char(24), and AUFK's AUFNR (Order Number) field, which is char(12).
    >
    > The problem I'm having is this:  All of the values in AUFNR are preceeded by two zeros.  For example, if I have a MEASURE value of '5200000017', the corresponding value in AUFNR is '005200000017'.  Because I have my SQL statement coded to just match the two fields, I obviously get no records returned because, I assume, of those leading zeros.
    > Dave
    You can't do a join like this in SAP's open SQL.  You could do it in real SQL ie EXEC.... ENDEXEC by using SUSBTR to strip off the leading zeros from AUFNR but this would not be a good idea because a)  modifying a column in the WHERE clause will stop any index on that column being used and b) using real SQL rather than open SQL is really not something that should be encouraged for database portability reasons etc. 
    Forget about a database join and do it in two stages; get your AUFK data into an itab, strip off the leading zeros, and then use FAE to get the FMIFIIT data (or do it the other way round). 
    I do hope you've got an index on your FMIFIIT MEASURE field (we don't have one here); otherwise your SELECT could be slow if the table holds a lot of data.

  • Multiple SQL statement in one step of procedure

    Hi,
    is it possible to run more than one sql command in only one step of a procedure.
    I need to run a script which insert about 2-300 records and i don't want to create 2-300 step.. any suggestions ?
    i tried :
    insert into myTable (myCol, myCol2) values('value1','value2');
    insert into myTable (myCol, myCol2) values('value2','value2');
    insert into myTable (myCol, myCol2) values('value3','value2');
    but it doesn't work!

    Hi,
    Why don't you try to write all your data:
    value1;value2 etc... in a file and create an interface that load this data to your table?
    Any way if you are in Oracle database try the begin end block as it said.
    or write a jython script to do the job.

  • Get Current SQL in Before delete trigger

    Hi,
    I have created a before delete trigger to track which records are deleted from a table I need to know what statements fires the trigger. can someone please describe how I can retrieve the current SQL.
    using sys_context('userenv','CURRENT_SQL') returns null for CURRENT SQL
    Note:
    For me the easier is to enable auditing and audit delete on the table however at the moment I cant get a downtime from the business to bounce the database to enable auditing.
    CREATE OR REPLACE TRIGGER before_delete BEFORE DELETE
    ON AUDIT_TEST_TAB
    FOR EACH ROW
    DECLARE
    v_username varchar2(50);
    v_stmt varchar2(255);
    v_client_info varchar2(200);
    v_os_user varchar2(50);
    v_machine varchar2(50);
    v_program varchar2(50);
    v_module varchar2(50);
    v_auth_type varchar2(200);
    v_ip_addr varchar2(200);
    v_sql_statement VARCHAR2(4000);
    BEGIN
    SELECT sys_context ('USERENV', 'CURRENT_SQL')
    INTO v_sql_statement
    FROM dual;
    -----------insert into logging table statment ----
    end;

    A few comments.
    Lets assume you run a delete statement that deletes 550 rows from your table. If your trigger is working then the very same statement would be stored 550 times. I think an BEFORE or better an AFTER delete STATEMENT level trigger would be the better choice. Why AFTER? Because if the delete operation fails, for example because of existing child records, then everything is rolled back anyway to the implicit savepoint just before the delete.
    So to store the SQL statement the correct trigger would be an AFTER STATEMENT DELETE trigger.
    Now what to store: You want the sql statement. You could try to find the cursor/currently running SQL. It might be tricky to separate that from the SQLs that you run to find this out.
    It could even be possible to simply save all commands that are in your PGA/Cached cursor area. First find out yur session, then store the SQL_text (first 60 chars) for all the cursors in this session by using v$open_cursor or the first 1000 chars by using v$sql.
    Here are a few views that might be helpful. v$session , v$open_cursor, v$sql, v$sqltext, v$sql_bind_data, v$sql_bind_capture, dba_hist_sqltext

  • Writing mulitple sql statements in 1 stored procedure

    Hi all, can i know how to create mulitple sql statements in 1 stored procedure??
    Eg the first sql statement will generate few results and my second sql statement will based on the first statement result to execute its second results and my third sql statements will on the second results to generate the final results which will be passed back to jsp pages as a resultset??
    For the time being, i only know how to create a single sql statement in one stored procedure..i had surf through the oracle website but cant find any solution. Can anyone help me?? Samples or links to any website will do.. Thanks alot...

    Hi Irene,
    If I understand your question correctly, then I have already written
    a similar (PL/SQL) stored procedure without any problems.
    However, I do think your question is more suited to the following
    forum:
    http://forums.oracle.com/forums/forum.jsp?id=478021
    I also think it will help others to answer your question if you
    include the following information:
    1. Version of Oracle you are using.
    2. The error message you are getting.
    3. The part of your code that is causing the problem.
    Also, have you looked at the following web sites?
    http://asktom.oracle.com
    http://metalink.oracle.com
    Good Luck,
    Avi.

  • How to put the SQL-statement returned value into the field (as a default)

    Hi,
    I am using Developer/2000 (Forms Designer) under windows 98.
    Please tell me how to put the SQL-statement value (as a default value) into the field before enter-query mode. Noted that I have tried the following ways but still some problems:-
    1) Place the SQL-statement into PRE_QUERY trigger in the form/block level.
    There is a message box which ask 'Do you want to save the changes?'.
    2) Place the SQL-statement before execute enter_query. There is still a
    message box which ask 'Do you want to save the changes?'.
    Any hints? Thanks. Urgent.

    solved it!
    1) Suppress DEFAULT save message
    if form_failure then
    raise form_trigger_failure;
    end if;
    2) Place the default value before enter-query.
    Ref: Title='Default value in query field in ENTER_QUERY mode' in designer forum by CVZ
    form level trigger
    ============
    WHEN-NEW-ITEM-INSTANCE
    =======================
    if :system.mode = 'ENTER-QUERY' then
    :block.item := 'default waarde';
    end if;
    3) Suppress the changes whenever leaving the default field.
    if :block.item is null then
    -- assign statement
    end if;

  • Spooling Extracts from Multiple SQL statements in 1 File

    Hi all,
    I am trying to spool extract results of 3 separate SQL statements into one single file. I wrote a SQL block similar to the one below. However, the result of the statements overwrite each other: 3 overwrote 2 and overwrote 1. Any suggestion how to combined there extracted results in one file?
    spool c:\test.txt
    <SQL statement 1>
    <SQL statement 2>
    <SQL statement 3>
    /spool OFF
    Thanks in advance
    Jason

    Please paste you SQL file here. These is no way one should overwrite another.
    Eric

  • Union SQL Statements in a DataTemplate

    I am in the process of converting a bunch (150+) BI Answers reports into about 9 Publisher reports(we have 9 dashboards now).
    Due to business logic and other considerations I have a large amount of reports that leverage unions.
    How do I have to handle SQL Unions statements in a Data Template?
    Do I have to break them up?
    How do I map multiple data sources to one data element name. I have some instances where four or five different SQL statements make one BI Report
    ie
    <element name="PublisherName" value="BIAnswers1"/>
    <element name="PublisherName" value="BIAnswer2"/>
    <element name="PublisherName" value="BIAnswers3"/>

    I had to go back to the orginal SQL with the union. Wha tI don't understand is that I get the correct amount of rows but the fields do not seem to be mapped correctly. They are all blank. I get the 20 rows I need to get but no data is in any of the elements.
    I can check the SQL in the BI answers direct sql function and it functions as desired.
    XML:
    <dataQuery>
              <sqlStatement name="CallData">
              <![CDATA[SELECT saw_0, saw_1 FROM ((SELECT "- Reporting Date"."Reporting Month" saw_0, FILTER(FILTER("- CMS Call Metrics"."# CMS Calls Answered" USING (("- CMS Details"."CMS Interval" = 0.00) AND ("- VDN Details"."VDN Area" = 'SVC') AND ("- VDN Details"."VDN Business Unit" = 'HLT') AND ("- Reporting Date"."Reporting Date" Between "- VDN Details"."VDN Start Date" and "- VDN Details"."VDN End Date"))) USING ("- VDN Details"."VDN Partner" = 'UHG')) saw_1 FROM Finance WHERE ("- Reporting Date"."Reporting Year" =  VALUEOF("CURRENT_YEAR")) AND ("- Reporting Date"."Reporting Month" <>  VALUEOF("CURRENT_MONTH"))) UNION (SELECT "- Reporting Date"."Reporting Month" saw_0, 0 saw_1 FROM Finance WHERE "- Reporting Date"."Reporting Year" =  VALUEOF("CURRENT_YEAR"))) t1 ORDER BY saw_0
    ]]></sqlStatement>
         </dataQuery>
         <dataStructure>
              <group name="CallData" source="CallData">
                        <element name="REPORTINGMONTH" value="saw_0"/>
                        <element name="CALLSANSWERED" value="saw_1"/>
              </group>

  • How to isolate the Sql Statement from Java Code

    Hi
    I Need to know that can we segregate the Sql Statements and convert them to Stored Procedures so as to isolate the Sql statements from Java Code.
    So i have one static web page which uses four select Statements so what i want is to create a stored procedure encapsulating these queries. So that the Java Web Developer will simply call the Stored Procedure instead of using four different SQL Statements.
    Suppose the developer has these four Statements
    Select ename,empno,sal,job from emp;
    select empno,ename,mgr from emp;
    select deptno,dname from dept;
    select emp.ename,emp.empno,emp.deptno,dept,dname fromemp,dept;
    So can i encapsulate these four Sql Statements in one Procedure and the Web developer can call the Store procedure and dont need to write the Sql Statements in his code.
    Can Anybody guide me how to write this Stored type of Store procedure.
    Thanks

    http://www.google.com/search?q=java+windows+registry
    Next time, search yourself. It might be beyond your belief, but you're really, really not the first person to wonder about this.

  • How to join multiple SQL statements?

    I'm try to combine four of the following SQL statements as one, and I basically want to group by the new combined sql statement by suspension
    Using: Oracle 10g
    Here's my sql statements/what I've tried but doesn't seem to work:
    select *
    from
    --NBA
    select
           decode (t.league_id, 1 , 'NBA') as League,
           t.moniker as First,
           t.Last_name as Last,
           (t.To_Team_Name || ' ' || To_Team_Nickname) as Team,
           count(*) Suspensions
    from   customer_data.cd_bk_trans t,
           customer_data.cd_bk_roster r
    where  t.player_id = r.player_id
    and    t.trans_type_id in (12,13,14)
    and    r.status = 'Y'
    and    r.league_id = 01
    group by t.league_id,t.last_name, t.moniker, t.to_team_name,t.to_team_nickname
    order by Suspensions desc
    union
    --MLB
    select
           decode (t.league_id, 7 , 'MLB') as League,
           t.moniker as First,
           t.Last_name as Last,
           (t.from_Team_Name || ' ' || from_Team_Nickname)as Team,
           count(*) Suspensions
    from   customer_data.cd_baseball_trans t,
           customer_data.cd_baseball_roster r
    where  t.player_id = r.player_id
    and    t.comments like '%Susp%'
    and    r.status = 'Y'
    and    r.league_id = 07
    group by t.league_id,t.last_name, t.moniker, t.from_team_name,t.from_team_nickname
    order by Suspensions desc
    union
    --NHL
    select
           decode (r.team_id,18, 'NHL') as League,
           t.fn as First,
           t.ln as Last,
           (t.from_Team_Name || ' ' || from_Team_Nickname)as Team,
           count(*) Suspensions
    from   customer_data.cd_nhl_trans t,
           customer_data.cd_nhl_roster r
    where  t.player_id = r.player_id
    and    t.trans_type in (10,11,12)
    and    r.status = 'Y'
    and    r.league_id = 18
    group by r.league_id, t.ln, t.fn, t.from_team_name,t.from_team_nickname
    order by Suspensions desc
    union
    --NFL
    select
           decode (t.league_id, 8, 'NFL') as League,
           t.moniker as First,
           t.last_name as Last,
           (t.from_Team_Name || ' ' || from_Team_Nickname)as Team,
           count(*) Suspensions
    from   customer_data.cd_football_trans t,
           customer_data.cd_football_roster r
    where  t.player_id = r.player_id
    and    t.trans_type_id in (24,25)
    and    r.status = 'Y'
    and    r.league_id = 8
    group by  t.league_id, t.last_name, t.moniker,           t.from_team_name,t.from_team_nickname
    order by  Suspensions desc
    Order by Suspensions desc

    Hi,
    Remove the ORDER BY clause in all the queries expcept lastone. Then it will work.
    You can have the ORDER BY clause in the last query of the inline view. Otherwise it will give the error.
    Run the query given below
    SELECT *
    FROM (
    --NBA
    SELECT decode(t.league_id, 1, 'NBA') AS league,
    t.moniker AS FIRST,
    t.last_name AS LAST,
    (t.to_team_name || ' ' || to_team_nickname) AS team,
    COUNT(*) suspensions
    FROM customer_data.cd_bk_trans t, customer_data.cd_bk_roster r
    WHERE t.player_id = r.player_id
    AND t.trans_type_id IN (12, 13, 14)
    AND r.status = 'Y'
    AND r.league_id = 01
    GROUP BY t.league_id,
    t.last_name,
    t.moniker,
    t.to_team_name,
    t.to_team_nickname
    UNION
    --MLB
    SELECT decode(t.league_id, 7, 'MLB') AS league,
    t.moniker AS FIRST,
    t.last_name AS LAST,
    (t.from_team_name || ' ' || from_team_nickname) AS team,
    COUNT(*) suspensions
    FROM customer_data.cd_baseball_trans t,
    customer_data.cd_baseball_roster r
    WHERE t.player_id = r.player_id
    AND t.comments LIKE '%Susp%'
    AND r.status = 'Y'
    AND r.league_id = 07
    GROUP BY t.league_id,
    t.last_name,
    t.moniker,
    t.from_team_name,
    t.from_team_nickname
    UNION
    --NHL
    SELECT decode(r.team_id, 18, 'NHL') AS league,
    t.fn AS FIRST,
    t.ln AS LAST,
    (t.from_team_name || ' ' || from_team_nickname) AS team,
    COUNT(*) suspensions
    FROM customer_data.cd_nhl_trans t, customer_data.cd_nhl_roster r
    WHERE t.player_id = r.player_id
    AND t.trans_type IN (10, 11, 12)
    AND r.status = 'Y'
    AND r.league_id = 18
    GROUP BY r.league_id,
    t.ln,
    t.fn,
    t.from_team_name,
    t.from_team_nickname
    UNION
    --NFL
    SELECT decode(t.league_id, 8, 'NFL') AS league,
    t.moniker AS FIRST,
    t.last_name AS LAST,
    (t.from_team_name || ' ' || from_team_nickname) AS team,
    COUNT(*) suspensions
    FROM customer_data.cd_football_trans t,
    customer_data.cd_football_roster r
    WHERE t.player_id = r.player_id
    AND t.trans_type_id IN (24, 25)
    AND r.status = 'Y'
    AND r.league_id = 8
    GROUP BY t.league_id,
    t.last_name,
    t.moniker,
    t.from_team_name,
    t.from_team_nickname
    ORDER BY suspensions DESC)
    ORDER BY suspensions DESC

  • How to execute multiple sql statements

    hi all
    i am wondering if i can execute multiple sql statements in one shot with >> execute immediate command
    for example:
    i define the variable as X := sql statement
    Y := sql statement
    z := sql statement
    can i do execute immediate (X,Y, Z);
    if yes how ?? and if not any possible alternate
    thanks

    Starting with Ganesh's code
    DECLARE
       l_statement                 VARCHAR2 (2000);
       v_passwd                    VARCHAR2 (200);
       v_username                  VARCHAR2 (200) := 'test';
       v_pwd_key                   VARCHAR2 (200) := 'lwty23';
       v_dblink_name               VARCHAR2 (2000);
       v_dblink_drop               VARCHAR2 (2000);
       v_dblink_create             VARCHAR2 (2000);
       v_dblink_check_connection   VARCHAR2 (2000);
       l_number                    NUMBER;
    BEGIN
       --<<c_instance>>
       FOR c_instance IN (SELECT *
                            FROM v_oracle_instances
                           WHERE environment = 'Developement')
       LOOP
          SELECT encpwd_owner.display_db_encpwd (v_username,
                                                 c_instance.host_name,
                                                 c_instance.instance_name,
                                                 v_pwd_key)
            INTO v_passwd
            FROM DUAL;
          v_dblink_name := c_instance.host_name || '_' || c_instance.instance_name;
          v_dblink_create :=
                ' CREATE DATABASE LINK '
             || v_dblink_name
             || ' CONNECT TO '
             || v_username
             || ' '
             || 'IDENTIFIED BY '
             || v_passwd
             || ' USING'
             || ' ''(DESCRIPTION=
    (ADDRESS=(PROTOCOL=TCP)(HOST= '
             || c_instance.host_name
             || ')(PORT='
             || c_instance.LISTENER_PORT
             || '))(CONNECT_DATA=(SID='
             || c_instance.instance_name
             || ')))''';
          v_dblink_check_connection := 'select 1 from global_name@' || v_dblink_name || '.QCM';    --- Notice this change. I am simply selecting 1. That should be enough to test the database link.
          v_dblink_drop := 'drop database link ' || v_dblink_name || '.QCMTLAF';
          -- l_statement := 'BEGIN ' || v_dblink_create ';' || v_dblink_check_connection ';' || v_dblink_drop '; END ;'
          BEGIN
              EXECUTE IMMEDIATE (v_dblink_create);
              DBMS_OUTPUT.PUT_LINE ('DB Link ' || v_dblink_name || ' Created');
         EXCEPTION
            WHEN others THEN
               dbms_output.put_line( 'Failed to create the database link ' || v_dblink_name  );
               dbms_output.put_line( dbms_utility.format_error_backtrace() );
               INSERT INTO error_table( column_list )
                 VALUES( <<list of values>> );
         END;
          EXECUTE IMMEDIATE (v_dblink_check_connection) INTO l_number;    --- Notice this.
          DBMS_OUTPUT.PUT_LINE ('DB Link ' || v_dblink_name || ' Tested');
          BEGIN
             EXECUTE IMMEDIATE (v_dblink_drop); 
             DBMS_OUTPUT.PUT_LINE ('DB Link ' || v_dblink_name || ' Dropped');
          EXCEPTION
             WHEN others THEN
               dbms_output.put_line( 'Failed to drop the database link ' || v_dblink_name  );
               dbms_output.put_line( dbms_utility.format_error_backtrace() );
               INSERT INTO error_table( column_list )
                 VALUES( <<list of values>> );
         END;
       END LOOP;
    END;But I agree with the point that others have brought up that it really doesn't make sense to create and drop a database link like this.
    Justin

  • SQL statement for calculating performance targets

    Hi
    I have taken of the admin of a database which stores project goals and scores. I have to develop a way to calculate how well all projects meet these scores. The table concerned is called goal and looks like this:
    goal
    goal_name
    project_code
    current_value
    good_value
    bad_value
    This can be for many different goals, for example if a project wants to get up a goal of having no more than 5 bugs in the project. I can also set a bad value, say 20, so if any projects have 20 or more bugs, triggers or alerts can be sent So I can enter into this table. The reason for putting 5 for good not 20 is because these scores are to be realistic.
    project_code = foo
    goal_name = software bugs
    good_value = 5
    bad_value = 20
    However, some goals may have the values switched and be in a much higher range, or may even be a percentage. For example one for number of sales could be
    project_code = foo
    goal_name = software sales
    good_value = 200
    bad_value = 50
    or project delay
    project_code = foo
    goal_name = sproject delay
    good_value = 0%
    bad_value = 50%
    i am trying to develop a SQL statement so I can get a % score of how well a goal is performing, so I can see
    What is the goal % for all foo goals
    Or what is the goal % for goal 'software sales'
    And also more importantly, how well are the goals doing globally.
    The requirement for doing this is using a single SQL statement, well, one SQL statement for the requirements I listed above, so for example the semantics are
    SELECT average(goal perforance) WHERE .... project = foo .... or goal = software sales... etc
    I am having trouble doing this, I have been banging my head against mydesk all day. the biggest thing is thowing me off is that the good value can be higher or lower than the bad value, and I am having trouble visualizing how to but this conditional statement in SQL
    One more thing, the percentage returned should never be more than 0% or 100%.
    If anyone has any ideas or pointers, please help me out,
    Thanks for your time,
    Message was edited by:
    user473327

    I am having trouble doing this, I have been banging
    my head against mydesk all day. the biggest thing is
    thowing me off is that the good value can be higher
    or lower than the bad value, and I am having trouble
    visualizing how to but this conditional statement in
    SQLI haven't looked at your requirements in detail cos I don't have time for such cumbersome tasks. However, you could have two UNION'd select statements, one which caters for the good > bad and one which caters for the good < bad. Also and alternative would be the use of DECODE or CASE statements in your select which are good for switching things around based on conditions.
    ;)

  • Getting difference from values of two different SQL Statements

    Hello,
    I have two SQL Queries like the following:
    1. Statement:
    SELECT name, SUM(a1), SUM(b1),SUM(c1),SUM(d1)
    FROM table 1, table 2
    WHERE ...
    GROUP BY name
    2. Statement:
    SELECT name, SUM(a2), SUM(b2),SUM(c2),SUM(d2)
    FROM table 3, table 4
    WHERE ...
    GROUP BY name
    I need now a combination of these SQL Statements in one Statement where the result should be the following records
    name, a1-a2 as a, b1-b2 as b, c1-c2 as c, d1-d2 as d
    Name is a VARCHAR and in both queries the values of the field name are the same
    all other fields are integer.
    I hope someone can help me.
    Regards

    You can use this
    with t1 as (
              SELECT name, SUM(a1) as a1, SUM(b1) as b1,SUM(c1) as c1,SUM(d1) as d1
              FROM table 1, table 2
              WHERE ...
              GROUP BY name
         ), t2 as (
              SELECT name, SUM(a2) as a2, SUM(b2) as b2,SUM(c2) as c2,SUM(d2) as d2
              FROM table 3, table 4
              WHERE ...
              GROUP BY name     
         ), tt as (
              select name
              from t1
              union
              select name
              from t2
    select *
    from tt
         natural left outer join t1
         natural left outer join t2
    where a1 <> a2
         or b1 <> b2
         or c1 <> c2
         or d1 <> d2Bye Alessandro

Maybe you are looking for

  • Error while transporting the cube

    Hi all, While I was transporting my cube from Development box to Acceptance box, following error occured.    Execution of programs after import (XPRA)    Transport request   : GCDK905220    System              : NCA    tp path             : /usr/sap/

  • Multiple device in one household help with iCloud

    My son and I both have Iphones. We have separate Apple ID's for icloud. Is there any way that we both connect to my existing Itunes account with separate Apple ID's?

  • Firewire 400 to firewire 800 adaptor

    Hello everyone, I just recentley upgraded from my 1.6 GHz PowerPC G5 to a Mac Pro 3.2 GHz Quad-Core Intel Xeon, with 8 gigs of ram. Now my problem is that I'm trying to figure out if there is an option for my firewire 400 Lacie harddrives to be conne

  • Production database Alert log Message

    Hi, I am using oracle 10gR1 on windows.Recently i have created a physical standby database (sid=smtm) and production database (sid=mtm).My production alter log file dispaly some thing like please suggest my what it shows. Mon Mar 02 00:18:31 2009 Pri

  • Photo sizes and adobe software

    Hi I'm attempting to make my first web banner in illustrator. I have a photo that I bought of Istockphoto, it is 851 x 546 px I created a new document in Illustrator 800 x 400 px. I then opened up the photo in illustrator and it opened in a new docum