May 22, 2012 at 1:13 pm
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
May 22, 2012 at 1:18 pm
Can you be a little more specific about your problem?What is, or isn't happening? Are you getting some kind of error message?
May 22, 2012 at 1:24 pm
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;
May 22, 2012 at 1:25 pm
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))
May 22, 2012 at 1:26 pm
Yessssss Thank You!!!
May 22, 2012 at 1:28 pm
You may need to make a slight change to the insert when a person loses. I just copied what was from the won side.
May 22, 2012 at 1:29 pm
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
Viewing 7 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply