SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Urgent help trigger
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

programer
Posting Yak Master

Slovenia
217 Posts

Posted - 09/27/2013 :  11:20:38  Show Profile  Reply with Quote
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

India
52317 Posts

Posted - 09/28/2013 :  06:09:31  Show Profile  Reply with Quote

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


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000