Please help i would like to return the division as the returned values
ALTER PROCEDURE [dbo].[DIVISONUPDATE] AS
BEGIN
DECLARE @admno nvarchar(50)
DECLARE @engrade INT
DECLARE @engscore INT
DECLARE @sstscore INT
DECLARE @sstgrade INT
DECLARE @sciencegrade INT
DECLARE @sciencescore INT
DECLARE @mathscore INT
DECLARE @mathsgrade INT
DECLARE @Totalgrades INT
DECLARE @Sum INT = 0
DECLARE @Counter INT, @TotalCount INT
SET @Counter = 1
SET @TotalCount = (SELECT COUNT(*) FROM temp)
WHILE (@Counter <= @TotalCount)
BEGIN
SET @admno = (SELECT admno FROM (SELECT ROW_NUMBER() OVER( ORDER BY (SELECT 0)) RowId,* FROM temp) t WHERE t.RowId = @Counter)
SET @engrade = (SELECT engrade FROM (SELECT ROW_NUMBER() OVER( ORDER BY (SELECT 0)) RowId,* FROM temp) t WHERE t.RowId = @Counter)
SET @sstgrade = (SELECT sstgrade FROM (SELECT ROW_NUMBER() OVER( ORDER BY (SELECT 0)) RowId,* FROM temp) t WHERE t.RowId = @Counter)
SET @sciencegrade = (SELECT sciencegrade FROM (SELECT ROW_NUMBER() OVER( ORDER BY (SELECT 0)) RowId,* FROM temp) t WHERE t.RowId = @Counter)
SET @mathsgrade = (SELECT mathsgrade FROM (SELECT ROW_NUMBER() OVER( ORDER BY (SELECT 0)) RowId,* FROM temp) t WHERE t.RowId = @Counter)
SET @Totalgrades = (SELECT Totalgrades FROM (SELECT ROW_NUMBER() OVER( ORDER BY (SELECT 0)) RowId,* FROM temp) t WHERE t.RowId = @Counter)
IF @Totalgrades >=4 and @Totalgrades<=12
BEGIN
IF @engrade='9' Or @sstgrade='9' Or @sciencegrade='9' Or @mathsgrade='9'
UPDATE temp SET Division = '2' WHERE admno = @admno
ELSE
UPDATE temp SET Division = '1' WHERE admno = @admno
END
ELSE IF @Totalgrades >=13 and @Totalgrades<=23
BEGIN
IF @engrade='9' Or @sstgrade='9' Or @sciencegrade='9' Or @mathsgrade='9'
UPDATE temp SET Division = '3' WHERE admno = @admno
ELSE
UPDATE temp SET Division = '2' WHERE admno = @admno
END
ELSE IF @Totalgrades >=24 and @Totalgrades<=29
BEGIN
IF @engrade='9' Or @sstgrade='9' Or @sciencegrade='9' Or @mathsgrade='9'
UPDATE temp SET Division = '3' WHERE admno = @admno
ELSE
UPDATE temp SET Division = '3' WHERE admno = @admno
END
ELSE IF @Totalgrades >=30 and @Totalgrades<=34
BEGIN
IF @engrade='9' Or @sstgrade='9' Or @sciencegrade='9' Or @mathsgrade='9'
UPDATE temp SET Division = '4' WHERE admno = @admno
ELSE
UPDATE temp SET Division = '4' WHERE admno = @admno
END
ELSE IF @Totalgrades >=34 and @Totalgrades<=36
BEGIN
UPDATE temp SET Division = 'U' WHERE admno = @admno
END
ELSE IF ISNULL(@Totalgrades,'') = ''
BEGIN
UPDATE temp SET Division = 'X' WHERE admno = @admno
END
SET @Counter = @Counter + 1
CONTINUE;
END
END