ALTER PROCEDURE [SchoolDemo].[UpdateSlot]
@EveningID int,
@SlotNotes varchar(250)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @StartDateTime varchar(50)
declare @EndDateTime varchar(50)
declare @SlotInterval int
select @StartDateTime= (select StartDateTime from dbo.tblEvening where EveningID=@EveningID)
select @EndDateTime= (select EndDateTime from dbo.tblEvening where EveningID=@EveningID)
select @SlotInterval= (select SlotInterval from dbo.tblEvening where EveningID=@EveningID)
while DateDiff(minute,@StartDateTime, @EndDateTime) > 0
begin
insert into dbo.tblSlot (EveningID,SlotStartTime,SlotEndTime,SlotEnabled,SlotNotes)
values(@EveningID,@StartDateTime,dateadd(minute,@SlotInterval,@StartDateTime),1,@SlotNotes)
select @StartDateTime=(dateadd(minute,@SlotInterval,@StartDateTime))
end
Tuesday, November 17, 2009
The statements are repeatedly performed until the condition is met.
Labels:
how to,
loop,
Sp,
sql,
sql server,
storc procedure,
t-sql,
while
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment