Now I want to write a SQL stored procedure, which is mainly to determine whether the current two weeks are working hours every day, and then I will have a database table of my own for corresponding update operation to output the work calendar that conforms to my company. The problem encountered now is that the trigger format is not nested, and SQL statements can be executed, but if applied, an error will be reported. The error information is as follows: Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32). (beyond the maximum stored procedure, function, trigger or view nesting level). Please be kind to see the cause of the problem. The code is as follows:
-- First, create a real table to store the results create table TempTime99 ( DDay datetime, --Traversal date WWeeks varchar(50), --Week of date Whether varchar(50) --Is the date a working day ) --The first is to create a OATIME Stored procedures for create procedure OATIME011 --Start defining content as begin --Values to be used after definition declare @today datetime declare @startday datetime --Date of the first day of opening permission declare @endday datetime --Date of last day of opening permission declare @dday datetime --Is the date to traverse after set @today = getdate() set @startday = convert(varchar(10),getdate()-(datepart(weekday,getdate())+5),111) set @endday = convert(varchar(10),@today+(8-datepart(weekday,@today)),111) set @dday = convert(varchar(10),@today+(8-datepart(weekday,@today)),111) --Equivalent to last day --start while Circular launch while @dday >= @startday begin --The day of the day defined corresponds to the day of the week declare @weeks int set @weeks = datepart(weekday,@dday+@@DATEFIRST-1) --Is the defined day a working day declare @whether int --Be used as if Judge whether the output is a working day if @weeks = 1 begin set @whether = 0 end if @weeks = 2 begin set @whether = 0 end if @weeks = 3 begin set @whether = 0 end if @weeks = 4 begin set @whether = 0 end if @weeks = 5 begin set @whether = 0 end if @weeks = 6 begin set @whether = 1 end if @weeks = 7 begin set @whether = 1 end --Condition to determine whether the current date is in the formal table. If not, insert IF NOT EXISTS ( SELECT * FROM TempTime97 WHERE @dday = TempTime97.DDay ) insert into TempTime97(DDay,WWeeks,Whether) select CONVERT(varchar,@dday,111) as date, @weeks as What day is it, @whether as Is it a working day --Condition determines whether the current date is in the formal table. If it exists, it will be updated IF EXISTS ( SELECT * FROM WORKTIME_SPECIALDAY WHERE @dday = WORKTIME_SPECIALDAY.DATE_NUM ) update t1 set t1.Whether = t2.IS_REST from TempTime97 t1,WORKTIME_SPECIALDAY t2 where t1.DDay=@dday --Condition determines whether the current date is in the formal table. If it exists, it will be updated IF EXISTS ( Select * from TempTime97 where DDay < @startday) delete from TempTime97 where DDay < @startday set @dday = @dday -1 end end execute OATIME011