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)
 trigger

Author  Topic 

programer
Posting Yak Master

221 Posts

Posted - 2011-12-12 : 12:52:30
I have a table tbl_Details and tbl_DetailsEvents.

Structure

tbl_Details:
Id, UserId, Amount, Winnings
1, uuuu, 13.25 Lost

tbl_DetailsEvents:
Id, DetailsId, Description, Odds , IsWinning
1, 1, Description1, 1.25, false
2, 1, Description2, 2.50, true


In the first table tbl_Details is Winnings = "Lost", because is in the second table tbl_DetailsEvents is "false" and "true".

If is in the column IsWinning ="true", is in the first table tbl_Details of the column Winning = "Win" .

I think for this situation is the best way to use trigger?
I need your help how to do with trigger or?

I tried trigger but does not works: Help

ALTER TRIGGER dbo.Update_BetSlipEvents
ON dbo.tbl_BetSlipEvents
AFTER INSERT--, UPDATE, DELETE
AS

UPDATE tbl_BetSlipDetails
SET
Winnings = CASE
WHEN i.IsWinning = 1 THEN 'Win'
WHEN i.IsWinning = 0 THEN 'Lost'
END
FROM tbl_BetSlipDetails d
INNER JOIN inserted i on i.BetSlipId = d.Id

programer
Posting Yak Master

221 Posts

Posted - 2011-12-12 : 13:29:54
1 1 10.1.2011 0:00:00 barcelona dsa dsa das NULL 1
5 1 10.1.2011 0:00:00 mona das das das NULL 1
6 1 10.1.2011 0:00:00 21 21 21 NULL NULL 0

UPDATE tbl_BetSlipDetails
SET
Winnings = CASE
WHEN i.IsWinning = 1 THEN 'win'
WHEN i.IsWinning = 0 THEN 'lost'
END
FROM tbl_BetSlipEvents d
INNER JOIN inserted i on i.BetSlipId = d.ID


How to always to show win if i have in database
3x = 1

If i have 1x=1 and 2x=0 returns: win.

I would like if you in columns IsWinnings=1

returns "win".

Go to Top of Page
   

- Advertisement -