Please help i have this code which randomly assigns colors.
Now my biggest challenge is i want to first check for most assigned colors then assign the less assign so as to balance the total number of color in stream and class.
My table has the following fields: Name, Class, Stream, Color how can i improve it.
USE [STORE]
GO
/****** Object: StoredProcedure [dbo].[Distributecolor] Script Date: 01/03/2022 12:29:13 PM ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[Distributecolor] AS
DECLARE @Random INT
DECLARE @Upper INT
DECLARE @Lower INT
SET @Lower = 1 ---- The lowest random number
SET @Upper = 5 ---- The highest random number
SELECT @Random = ROUND(((@Upper - @Lower -1) * RAND() + @Lower), 0)
---SELECT @Random
truncate table colorsdata
insert into colorsdata(color)
select case when @random ='1' then 'Blue' else case when @random='2' then 'Green' else case when @random ='3' then 'Yellow' else case when @random ='4' then 'Red' end end end end