Problems With if And else.

  • Hallo Again,

    I have A Problem running Two statment within the if clause.

    1. I need to select the result set.

    2. I need to insert data into A table.

    Thank you!!!

    CREATE PROCEDURE

    Casino.Sp_SlotMachine

    @UserNVARCHAR(10),

    @betINT

    AS

    BEGIN

    DECLARE @L_Wheel VARCHAR

    DECLARE @M_Wheel VARCHAR

    DECLARE @R_Wheel VARCHAR

    SET

    @L_Wheel =

    (

    select top 1 AA from

    Casino.Symbols

    AS alias

    order by newid()

    )

    SET

    @M_Wheel =

    (

    select top 1 BB from

    Casino.Symbols

    AS alias

    order by newid()

    )

    SET

    @R_Wheel =

    ( select top 1 CC from

    Casino.Symbols

    AS alias

    order by newid()

    )

    IF

    @M_Wheel = @R_Wheel AND @R_Wheel = @L_Wheel

    BEGIN

    (

    SELECT

    ('You Won') AS Status,

    @L_Wheel AS L_Wheel,

    @M_Wheel AS M_Wheel,

    @R_Wheel AS R_Wheel,

    @bet*2 AS Amount

    -- Here Is my Problem!--

    INSERT INTO Casino.BankTransaction (TranType,DateAndtime,Amount,RollAmount)

    VALUES ('Won',SYSDATETIME(),@bet,(@bet*2))

    )

    END

    ELSE

    BEGIN

    (

    SELECT

    ('You Lost ') AS Status,

    @L_Wheel AS L_Wheel,

    @M_Wheel AS M_Wheel,

    @R_Wheel AS R_Wheel

    )

    END

    END

  • Can you be a little more specific about your problem?What is, or isn't happening? Are you getting some kind of error message?

  • Is this what you are attempting to accomplish?

    CREATE PROCEDURE Casino.Sp_SlotMachine

    @User NVARCHAR(10)

    ,@bet INT

    AS

    BEGIN

    DECLARE @L_Wheel VARCHAR;

    DECLARE @M_Wheel VARCHAR;

    DECLARE @R_Wheel VARCHAR;

    SET @L_Wheel = (

    SELECT TOP 1 AA

    FROM Casino.Symbols AS alias

    ORDER BY newid()

    );

    SET @M_Wheel = (

    SELECT TOP 1 BB

    FROM Casino.Symbols AS alias

    ORDER BY newid()

    );

    SET @R_Wheel = (

    SELECT TOP 1 CC

    FROM Casino.Symbols AS alias

    ORDER BY newid()

    );

    IF @M_Wheel = @R_Wheel

    AND @R_Wheel = @L_Wheel

    BEGIN

    SELECT

    'You Won' AS STATUS

    ,@L_Wheel AS L_Wheel

    ,@M_Wheel AS M_Wheel

    ,@R_Wheel AS R_Wheel

    ,@bet * 2 AS Amount; -- -- Here Is my Problem!--

    INSERT INTO Casino.BankTransaction (

    TranType

    ,DateAndtime

    ,Amount

    ,RollAmount

    )

    VALUES (

    'Won'

    ,GETDATE()

    ,@bet

    ,(@bet * 2)

    );

    END;

    ELSE

    BEGIN

    SELECT

    'You Lost ' AS STATUS

    ,@L_Wheel AS L_Wheel

    ,@M_Wheel AS M_Wheel

    ,@R_Wheel AS R_Wheel;

    INSERT INTO Casino.BankTransaction (

    TranType

    ,DateAndtime

    ,Amount

    ,RollAmount

    )

    VALUES (

    'Lost'

    ,GETDATE()

    ,@bet

    ,(@bet * 2)

    );

    END;

    END;

  • ohhh Sorry ok,

    Msg 156, Level 15, State 1, Procedure Sp_SlotMachine, Line 61

    Incorrect syntax near the keyword 'INSERT'.

    Msg 102, Level 15, State 1, Procedure Sp_SlotMachine, Line 65

    Incorrect syntax near ')'.

    I'm trying to put insert after the select

    within the if clause.

    :

    INSERT INTO Casino.BankTransaction (TranType,DateAndtime,Amount,RollAmount)

    VALUES ('Won',SYSDATETIME(),@bet,(@bet*2))

  • Yessssss Thank You!!!

  • You may need to make a slight change to the insert when a person loses. I just copied what was from the won side.

  • simple syntax issue.

    you have BEGIN ( and ) END; the parentheses are not allowed

    cthis is syntactically correct:

    CREATE PROCEDURE Casino.SP_SLOTMACHINE

    @User NVARCHAR(10),@bet INT

    AS

    BEGIN

    DECLARE @L_Wheel VARCHAR

    DECLARE @M_Wheel VARCHAR

    DECLARE @R_Wheel VARCHAR

    SET @L_Wheel = (SELECT TOP 1 AA FROM Casino.Symbols AS alias ORDER BY NEWID())

    SET @M_Wheel = (SELECT TOP 1 BB FROM Casino.Symbols AS alias ORDER BY NEWID())

    SET @R_Wheel = (SELECT TOP 1 CC FROM Casino.Symbols AS alias ORDER BY NEWID())

    IF @M_Wheel = @R_Wheel

    AND @R_Wheel = @L_Wheel

    BEGIN

    SELECT

    ( 'You Won' ) AS Status,

    @L_Wheel AS L_Wheel,

    @M_Wheel AS M_Wheel,

    @R_Wheel AS R_Wheel,

    @bet * 2 AS Amount

    ---- Here Is my Problem!--

    INSERT INTO Casino.BankTransaction

    (TranType,DateAndtime,Amount,RollAmount)

    VALUES ('Won',SYSDATETIME(),@bet,( @bet * 2 ))

    END

    ELSE

    BEGIN

    (SELECT

    ( 'You Lost ' ) AS Status,

    @L_Wheel AS L_Wheel,

    @M_Wheel AS M_Wheel,

    @R_Wheel AS R_Wheel)

    END

    END

    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!

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

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