data transfer multiple tables with insert trigger

1 - how do convert first table to target second table in attached pictures

or

2 how do  make  third table in attached pictures

dd.png
ATTMANAsked:
Who is Participating?
 
ATTMANConnect With a Mentor Author Commented:
eror set tr in sql server 2008
0
 
Bill BachConnect With a Mentor PresidentCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.