## SQL and LOOP

I&#039;m trying to get 8 random images where the show column = &#039;YES&#039;.<BR>Here is the code.<BR><BR>CREATE PROCEDURE Random_Images <BR><BR>(@Rand_1 int = 0,<BR>@Rand_2 int = 0,<BR>@Rand_3 int = 0,<BR>@Rand_4 int = 0,<BR>@Rand_5 int = 0,<BR>@Rand_6 int = 0,<BR>@Rand_7 int = 0,<BR>@Rand_8 int = 0,<BR>@Random int=0,<BR>@MIN int = 0,<BR>@MAX int = 0)<BR><BR>AS<BR><BR><BR>SET @MIN = (SELECT MIN(pID) FROM Products)<BR>SET @MAX = (SELECT MAX(pID) FROM Products)<BR><BR>-- ** Guessing from here to<BR><BR>LOOP<BR>@Random = (rand()* (@MAX - @MIN)) + @MIN<BR><BR>IF @Random = (SELECT pID FROM Products WHERE pID = @Random AND Show = &#039;YES&#039;)<BR>@i = @i + 1<BR>SET @Rand_(@i) = @Random<BR>END IF<BR><BR>IF @i = 8<BR>EXIT<BR>END IF<BR><BR>END LOOP<BR><BR>-- ** Here<BR><BR>SELECT * FROM Products<BR><BR>WHERE pID IN (@Rand_1,@Rand_2,@Rand_3,@Rand_4,@Rand_5,@Rand_6,@ Rand_7,@Rand_8)<BR>GO<BR><BR>I&#039;m particularly concerned about this stament.<BR><BR>SET @Rand_(@i) = @Random<BR><BR>Is it possible to set a variable with a variable?<BR><BR>Any ideas/suggestions are apprecieated.<BR>jc