pardon this is the all my "stored procedure"i need to generate date backward from end to start Merci
DECLARE@shifts_pattern TABLE ([PatternId] [int] IDENTITY(1,1 ) NOT NULL, [patternShiftValue] [int]NOT NULL)declare@I intset@i=0while@i < 5BEGININSERT INTO @shifts_pattern ([patternShiftValue] )SELECT 1 UNION ALLSELECT 2 UNION ALLSELECT 3 UNION ALL SELECT 4 UNION ALLSELECT 5 UNION ALLSELECT 6 UNION ALLSELECT 7 UNION ALLSELECT 8set@i=@i+1enddeclare@empListTABLE( [empID] [numeric](18, 0) NOT NULL,[ShiftType] [int]NULL,[StartDate][datetime]NOT NULL,[EndDate] [datetime] NOT NULL) INSERT INTO@empList ([empID], [ShiftType],[StartDate],[EndDate])SELECT 111111,1,CONVERT(DATETIME, '01/01/2008', 103), CONVERT(DATETIME, '17/01/2008', 103)-- create shifts tabledeclare@empShiftsTABLE ( [empID] [numeric](18, 0) NOT NULL,[ShiftDate] [datetime]NOT NULL,[ShiftType] [int]NULL ,[StartDate] [datetime]NOT NULL,[EndDate] [datetime]NOT NULL) DECLARE@StartDate datetimeDECLARE@EndDate datetimeDeclare@current datetimeDEclare@last_shift_id intDeclare@input_empID int----------------- open list table for emp with curserDECLAREList_of_emp CURSOR FOR SELECTemp.empId,emp.ShiftType,emp.StartDate,emp.EndDate FROM @empList empOPENList_of_empFETCHList_of_emp INTO @input_empID , @last_shift_id ,@StartDate,@EndDateSET @current = @StartDate-- loop on all emp in the listwhile@@Fetch_Status = 0begin-- loop to insert info of emp shiftswhile@current<=@EndDate beginINSERT INTO @empShifts ([empID],[ShiftDate],[ShiftType],[StartDate] ,[EndDate])select @input_empID ,@current,shift .patternShiftValue ,@StartDate,@EndDatefrom @shifts_pattern as shift where PatternId=@last_shift_id+1 print ('-')set @last_shift_id=@last_shift_id+ 1set @current=DATEADD( d,1, @current)endFETCHList_of_emp INTO @input_empID ,@last_shift_id,@StartDate,@EndDate-- init of start date for the next empset@current = @StartDateendCLOSEList_of_empDEALLOCATE List_of_empselectempID,shiftDate,DATENAME (dw,shift.ShiftDate ), shiftType from @empShifts as shiftRETURN