SQL command returning -

  • Hi All,

    I run a online game, and sometimes a player will have neg stats. This is now causing neg score for neg stats.

    I would like to cap this at 0 if the stat is neg, but im not sure where I am going wrong.

    This is what I have so far.

    update #p set cashStealScore = @baseStealValue * b.score/@topCash * .4

    from #rankCashSteals b

    where #p.playerid = b.playerid

    Any help would be great!

    Thanks

    Anthony

  • I think what you want to do is to use a CASE statement to evaluate the b.score: if it's less than zero use zero, else use the b.score

     

    update #p 
    SET cashStealScore = @baseStealValue * CASE
    WHEN b.score < 0 THEN 0
    ELSE b.score
    END/@topCash * .4
    from #rankCashSteals b
    where #p.playerid = b.playerid

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Hi Lowell

    Oh my gosh! This worked perfectly!

    Thank you SO much!

    Anthony.

  • This was removed by the editor as SPAM

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

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