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.
Author |
Topic |
programer
Posting Yak Master
221 Posts |
Posted - 2013-06-19 : 11:33:14
|
My tables:tbl_Slip:ID Stake Odds Winnings1 10.00 15.00 0.002 10.00 15.00 0.003 10.00 15.00 0.00tbl_SlipDetails:ID SlipId IsWinning1 1 02 2 03 2 0Trigger:Update tbl_Slip set Winnings = Stake *Oddsfrom tbl_Slip as sinner join inserted as i on i.SlipId = s.Idwhere i.IsWinning = 1I want to calculate Stake*Odds if is in my casetbl_SlipDetails:ID SlipId IsWinning1 1 02 2 13 2 1if is:tbl_SlipDetails:ID SlipId IsWinning1 1 02 2 13 2 0no calculatedSo when isWinning is 2x = 1 is calculated. This is for my case.But if is:tbl_SlipDetails:ID SlipId IsWinning1 1 02 2 13 2 14 2 1IsWinning is 3x = 1.tbl_Slip.Id=tbl_SlipDetails.SlipIdPlease help |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-19 : 11:39:46
|
sorry your requirement is not clear. do you mean this?CREATE TRIGGER Trp_SlipDetailsON tbl_SlipDetailsFOR INSERT,UPDATEASBEGIN UPDATE s set s.Winnings = s.Stake * s.Oddsfrom tbl_Slip as sinner join inserted as ion i.SlipId = s.Idwhere i.IsWinning = 1END ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
programer
Posting Yak Master
221 Posts |
Posted - 2013-06-19 : 12:01:55
|
I tried to use your code but not works.My result is:2 10,00 15,00 150,00 Calculated IsWinning=1x. This is wrong.Stake*Odds calculated if are completed all conditions.In my case are completed all conditions when I updated:tbl_SlipDetails:ID SlipId IsWinning1 1 02 2 03 2 0To:tbl_SlipDetails:ID SlipId IsWinning1 1 02 2 13 2 1If istbl_SlipDetails:ID SlipId IsWinning1 1 02 2 13 2 0not calculated because IsWinning = 1 and 0. |
|
|
programer
Posting Yak Master
221 Posts |
Posted - 2013-06-19 : 14:01:47
|
quote: Originally posted by programer I tried to use your code but not works.My result is:2 10,00 15,00 150,00 Calculated IsWinning=1x. This is wrong.Stake*Odds calculated if are completed all conditions.In my case are completed all conditions when I updated:tbl_SlipDetails:ID SlipId IsWinning1 1 02 2 03 2 0To:tbl_SlipDetails:ID SlipId IsWinning1 1 02 2 13 2 1If istbl_SlipDetails:ID SlipId IsWinning1 1 02 2 13 2 0not calculated because IsWinning = 1 and 0.
Still I need your help. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-20 : 01:14:15
|
Your explanation is still not clear to me. You would be better illustrating with some sample data clearly if my below guess doesnt work CREATE TRIGGER Trp_SlipDetailsON tbl_SlipDetailsFOR INSERT,UPDATEASBEGIN UPDATE s set s.Winnings = s.Stake * s.Oddsfrom tbl_Slip as sinner join (SELECT i1.SlipId FROM inserted i1 INNER JOIN tbl_SlipDetails sd ON i1.SlipId = sd.SlipId GROUP BY i1.SlipId HAVING SUM(CASE WHEN sd.IsWinning = 0 THEN 1 ELSE 0 END) = 0 )as ion i.SlipId = s.IdEND ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
programer
Posting Yak Master
221 Posts |
Posted - 2013-06-20 : 04:12:23
|
quote: Originally posted by visakh16 Your explanation is still not clear to me. You would be better illustrating with some sample data clearly if my below guess doesnt work CREATE TRIGGER Trp_SlipDetailsON tbl_SlipDetailsFOR INSERT,UPDATEASBEGIN UPDATE s set s.Winnings = s.Stake * s.Oddsfrom tbl_Slip as sinner join (SELECT i1.SlipId FROM inserted i1 INNER JOIN tbl_SlipDetails sd ON i1.SlipId = sd.SlipId GROUP BY i1.SlipId HAVING SUM(CASE WHEN sd.IsWinning = 0 THEN 1 ELSE 0 END) = 0 )as ion i.SlipId = s.IdEND ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs
Thanks thanks works for me! |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-20 : 04:21:55
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|