data transfer multiple tables with insert trigger

Posted on 2009-12-24
Last Modified: 2012-05-08
1 - how do convert first table to target second table in attached pictures


2 how do  make  third table in attached pictures

Question by:ATTMAN
    LVL 28

    Assisted Solution

    by:Bill Bach
    ALTER TABLE tbl_records
    ADD COLUMN Value_1_Calculate INTEGER,
    ADD COLUMN Value_2_Calculate INTEGER,
    ADD COLUMN Value_3_Calculate INTEGER;

    UPDATE tbl_records tr SET
    Value_1_Calculate = value_1 - (SELECT TOP 1 t.value_1 FROM tbl_records t WHERE t.device_id = tr.device_id ORDER BY date_stamp),
    Value_2_Calculate = value_2 - (SELECT TOP 1 t.value_2 FROM tbl_records t WHERE t.device_id = tr.device_id ORDER BY date_stamp),
    Value_3_Calculate = value_3 - (SELECT TOP 1 t.value_3 FROM tbl_records t WHERE t.device_id = tr.device_id ORDER BY date_stamp)

    SELECT id, date_stamp, device_id, Value_1_Calculate as value_1_dif, Value_2_Calculate as value_2_dif, Value_3_Calculate as value_3_dif
    INTO new_tbl_dif
    FROM tbl_records WHERE Value_1_Calculate > 0

    Of course, this may ONLY work for the test data set provided.  As for a generic case, there are a few more variables to consider.

    Accepted Solution

    eror set tr in sql server 2008

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now