Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need Help with Multiplication

Author  Topic 

sanlen
Starting Member

29 Posts

Posted - 2008-11-22 : 05:45:27
Hi All,

I have two tables as below:

create table table1
(tbl1_id int identity(1,1), name varchar(30), paying_rate money
CONSTRAINT pk_table1_id PRIMARY KEY (tbl1_id)
)

create table table2
(tbl2_id int identity(1,1), tbl1_id int, project varchar(30), working_hour int, total money
CONSTRAINT fk_tbl1_id FOREIGN KEY (tbl1_id) REFERENCES table1(tbl1_id)
)

I want after inserting working_hour in that table2, then the total in table2 will equal to paying_rate (in table1) * working_hour (in table2)
Could you please advise??


Best Regard,
SANLEN

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-11-22 : 06:04:53
See http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=114927



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-22 : 11:05:46
[code]UPDATE t2
SET t2.total=t2.working_hour * t1.paying_rate
FROM table1 t1
INNER JOIN table2 t2
ON t2.tbl1_id = t1.tbl1_id
[/code]
Go to Top of Page
   

- Advertisement -