fahad sheikhji

fahad sheikhji

  • NA
  • 53
  • 56.6k

Better code for this ?

Mar 18 2012 1:49 AM
hi
here is my stored procedure
to increment roomno if it reaches to 32.for example in one room 32 students can sit so for that while inserting records from asp to sql that time if room no 101 reaches 32 students then while entering 101 that time it automatical increment to 102 and save records in sql table..
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go


ALTER PROCEDURE [dbo].[usp_InserttblRoomDisplay]
@RegNo1 varchar(50),
@Semister1 varchar(50),
@RegNo2 varchar(50),
@Semister2 varchar(50),
@RegNo3 varchar(50),
@Semister3 varchar(50),
@RegNo4 varchar(50),
@Semister4 varchar(50),
@RegNo5 varchar(50),
@Semister5 varchar(50),
@RegNo6 varchar(50),
@Semister6 varchar(50),
@RoomNo varchar(50)
AS
BEGIN

while (select count(RegNo1) from tblRoomDisplay where RoomNo=@RoomNo)>=32
while (select count(RegNo2) from tblRoomDisplay where RoomNo=@RoomNo)>=32
while (select count(RegNo3) from tblRoomDisplay where RoomNo=@RoomNo)>=32
while (select count(RegNo4) from tblRoomDisplay where RoomNo=@RoomNo)>=32
while (select count(RegNo5) from tblRoomDisplay where RoomNo=@RoomNo)>=32
while (select count(RegNo6) from tblRoomDisplay where RoomNo=@RoomNo)>=32

begin Set @RoomNo=@RoomNo + 1
end

insert into tblRoomDisplay(RegNo1,Semister1,RegNo2,Semister2,RegNo3,Semister3,RegNo4,Semister4,RegNo5,Semister5,RegNo6,Semister6,RoomNo) values(@RegNo1,@Semister1,@RegNo2,@Semister2,@RegNo3,@Semister3,@RegNo4,@Semister4,@RegNo5,@Semister5,@RegNo6,@Semister6,@RoomNo)
END

//but its not incrementing the roomno which i entered..can any one solve my problem..

can any one suggest me..thanks


Answers (1)