If Username in Result set update another table.

  • Hi,

    I need a hint for getting to the solution.

    I have two table :

    1.Bankroll (User the in casino and amount of money)

    2.BankTransaction ( Win,lost,bonus,withdraw etc')

    I need to build in the system that every Player that put more than 1000 dolar a bet will get 50 dollar bonus.

    My first of the solutions was the select the result , but i have a problem to update the bankroll table for for give every player bonus..

    SELECT

    Username

    ,SUM(AMOUNT) as amount

    FROM

    CASINO.BankTransaction

    WHERE

    DateAndTime >= DateAdd(hh, -24, GETDATE())

    AND

    Trantype LIKE 'Win'

    OR

    Trantype LIKE 'Lose'

    GROUP BY

    UserName

    HAVING

    SUM(amount) < 1000

    Can I have some hint for a better direction.???

    Best Regards!!! 🙂

  • Without table definitions, just a guess but maybe enough to get you on the right track

    Update Bankroll

    Set <whatever>

    FROM Bankroll inner join (SELECT

    Username

    FROM

    CASINO.BankTransaction

    WHERE

    DateAndTime >= DateAdd(hh, -24, GETDATE())

    AND

    (Trantype LIKE 'Win'

    OR

    Trantype LIKE 'Lose')

    GROUP BY

    UserName

    HAVING

    SUM(amount) < 1000 ) WinnersAndLosers ON <join condition here>

    Also note that you were missing brackets in the where clause that may have changed the meaning of the query from what you wanted.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Perfect!!!

    Thank you again...

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply