?
Solved

data transfer multiple tables with insert trigger

Posted on 2009-12-24
2
Medium Priority
?
355 Views
Last Modified: 2012-05-08
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
0
Comment
Question by:ATTMAN
2 Comments
 
LVL 29

Assisted Solution

by:Bill Bach
Bill Bach earned 2000 total points
ID: 26120239
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
 

Accepted Solution

by:
ATTMAN earned 0 total points
ID: 26128703
eror set tr in sql server 2008
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

809 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