I have the Homework to set up a Table for a Kicker Tournament. I have to write an INSERT statement where i will Fill the Goals for Player 1 and Player 2 with random numbers. So thats more or less clear. I got it like that :
DECLARE @MAX_VALUE INT = 10, @MIN_VALUE INT = 0, @RANDOM_NUMBER INT;
SELECT @Random_Number = FLOOR((@Max_Value - @Min_Value + 1)
* RAND() + @Min_Value)
DECLARE @RANDOM_NUMBER2 INT;
SELECT @Random_Number2 = FLOOR((@Max_Value - @Min_Value + 1)
* RAND() + @Min_Value)
INSERT INTO dbo.SpielTabelle
VALUES(4,1,3,@RANDOM_NUMBER,@RANDOM_NUMBER2)
Now the problem is if one Person has 10 (thats why max value 10) the person has won and i dont want that the second number is also 10. How can i include an if clause into this?
This is for SQL Server 2017, i tried to include an if clause but it didnt work. Always syntax fault.
DECLARE @MAX_VALUE INT = 10, @MIN_VALUE INT = 0, @RANDOM_NUMBER INT;
SELECT @Random_Number = FLOOR((@Max_Value - @Min_Value + 1)
* RAND() + @Min_Value)
DECLARE @RANDOM_NUMBER2 INT;
SELECT @Random_Number2 = FLOOR((@Max_Value - @Min_Value + 1)
* RAND() + @Min_Value)
INSERT INTO dbo.SpielTabelle
VALUES(4,1,3,@RANDOM_NUMBER,@RANDOM_NUMBER2)
I expect that when its final i can just put in the new Game ID and then it automatically will fill everything else in and every game has 1 person that has 10 goals and 1 that got less.
Aucun commentaire:
Enregistrer un commentaire