UNKNOWN --************************************** -- for :Date Ranges --************************************** Copyride GeekSoft Inc. --************************************** -- Name: Date Ranges -- Description:To enter records with sequential dates in a table. I extract the amount of days with the DateDiff function Which includes month jumps. My code to add sequential dates to a table also calculates month jumps. -- By: Rudolf Mouthaan -- -- -- Inputs:If implemented as a Stored Procedure it requires 3 parameters: @daysout int: the amount ofd days booked out @EQ_ID char: equipment ID to be booked @BeginDate datetime: first day booked out -- -- Returns:It will add a number of records to a table equal to the amount specified in the parameter(daysout). I created it for our Web based Equipment booking system(ASP). -- --Assumes:create this table: CREATE TABLE [dbo].[equip_out] ( [ID] [int] NOT NULL , [Equipment_ID] [varchar] (4) NULL , [From_date] [datetime] NULL ) ON [PRIMARY] GO -- --Side Effects:None --This code is copyrighted and has limited warranties. --Please see http://www.Planet-Source-Code.com/xq/ASP/txtCodeId.516/lngWId.5/qx/vb/scripts/ShowCode.htm --for details. --************************************** CREATE PROCEDURE DATERANGE @daysout int, @EQ_ID char, @BeginDate datetime AS declare @Reccount int declare @loopCount int declare @ID_Max as int declare @BeginDate datetime declare @dayCount int declare @monthCount int declare @yearCount int select @ID_Max = (select max(ID) from equip_out) select @loopCount = 0 select @dayCount = (select max(datepart(dd, from_date)) + 1 from equip_out) select @Reccount = 10 select @BeginDate = GetDate() select @monthCount = (select datepart(mm, from_date) from equip_out) select @yearCount = (select datepart(yyyy, from_date) from equip_out) WHILE @loopCount < @Reccount Begin Insert into Equip_out (ID, Equipment_ID, From_date) values ( (@ID_Max + 1), 'T1', ltrim(str(@monthCount)) + '/' + ltrim(str(@dayCount)) + '/' + ltrim(str(@yearCount)) ) select @loopCount = @loopCount + 1 select @dayCount = @dayCount + 1 If (SELECT DAY(DATEADD(d, -DAY(GETDATE()),DATEADD(m,1,GETDATE())))) < @dayCount begin select @dayCount = 1 select @monthCount = @monthCount + 1 end End