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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Urgent help trigger

Author  Topic 

programer
Posting Yak Master

221 Posts

Posted - 2013-09-27 : 11:20:38
Hi,

I have:

tbl_table1
Id, Calc1, IsWinning
1, 250,0
2, 350,0
4, 600,0

tbl_table2
Id, tbltable1id,Amount,Calculate
1, 1,4 , 10, 0

I updated in the tbl_table1 column IsWinning:
Id, Calc1, IsWinning
1, 2.50, 1
2, 3.50,0
4, 6.10,1

If is IsWinning 1 I need to update column Calculate 2.50*6.10*10:
tbl_table2
Id, tbltable1id,Amount,Calculate
1, 1,4 , 10, 152.50 - this is updated result

I hope you understand what I mean.


visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-09-28 : 06:09:31
[code]
CREATE TRIGGER Trig_table1
ON tbl_table1
FOR UPDATE
AS
BEGIN
UPDATE t
SET t.Calculate = Prdt * Amount
FROM tbl_table2 t
CROSS APPLY(SELECT EXP(SUM(LOG(Calc1))) AS Prdt
FROM tbl_table1
WHERE ',' + t.tbltable1id + ',' LIKE '%,' + CAST(id AS varchar(5)) + ',%')t1
END
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -