I've already, searched and read, many answers about this issue for 3 days, but couldn't get a clear answer on how to do this.
this will be a little long, be patient please.
First of all, I am trying to make a simple lottery app. I hope everyone of you know about the 6/49 lottery thing.
Well, according to game, first, for a week customers play lottery (lotteryTBL
). Then 6 numbers between 1-49 are selected as lucky numbers (resultsTBL
).
What I want to do is updating lotteryTBL
after a new result row is inserted into resultsTBL
.
Structure of lotteryTBL
:
ID num1 num2 num3 num4 num5 num6 draw_date howmanyknew
1 5 6 8 15 18 25 08-21-2015 0
2 7 15 18 30 40 45 08-21-2015 0
Structure of resultsTBL
:
ID num1 num2 num3 num4 num5 num6 draw_date
1 15 18 35 38 40 47 08-21-2015
Now, here is the pseudocode of what i want:
after insert a new row into resultsTBL
total <- 0
for each row in the lotteryTBL where lotteryTBL.draw_date = resultsTBL.draw_date
total <- calculate how many of them are the same with the resultsTBL's row.
update lotteryTBL set howmanyknew = total where "some condition"
First, I tried to do it with trigger, some said "it is dynamic sql, you cannot use trigger", some said "use stored procedure". And I did it too. But, they never worked.
Anyway, Can someone type a good pseudocode for this? which method do I have to use? what is the logic here?
Best Answer
I've made it in a
TRIGGER
calling aStored Procedure
insideresultsTBL
table.Table
lotteryTBL
andresultsTBL
:Inserting on
resultsTBL
:RESULT:
If you look in the
INSERT
:ID
= 1: 1,5.ID
= 2: 4,8,25,40.TRIGGER
:STORED PROCEDURE
: