Back to OIM Explorer

dbo.QBM_FGIScheduleNextRun

Scalar FunctionSQL_SCALAR_FUNCTIONSandbox DB

Scalar Function.

Source: sandbox-db sys.sql_modules

Source size: 8.907 characters

Interpretation

  • Database function. Usually supports views, validation, or calculated predicates; look at referenced-by entries for callers.

Relations

  • No extracted relations.

Typed Edges

  • references source dbo.QBM_FCVStringToList source text reference
  • references source dbo.QBM_FCVIntToString source text reference
  • references source dbo.QBM_FCVStringPadLeft source text reference
  • references source dbo.QBM_FCVStringToInt source text reference
  • references source dbo.QBM_FGITimeIsValid source text reference

Complete Source

SQL333 lines
1CREATE FUNCTION dbo.QBM_FGIScheduleNextRun(2  @oldnextrun datetime,3  @lastrun datetime,4  @JustNow datetime,5  @StartTime varchar(256),6  @FrequencyType nvarchar(16),7  @Frequency int,8  @FrequencySubType nvarchar(256),9  @CurrentUTCOffset int10) RETURNS datetime11AS12BEGIN13  DECLARE @nextrun datetime14  DECLARE @starttimes_intern QBM_YParameterlist15  DECLARE @lastrun_intern datetime16  DECLARE @oldnextrun_intern datetime17  DECLARE @Abends nvarchar(16)18  DECLARE @JustNowLocal datetime19  DECLARE @StartofPeriod datetime20  DECLARE @StartofNextPeriod datetime21  DECLARE @Wochentag varchar(16)22  SELECT @Abends = N ' 23:59:59.999'23  SELECT24    @JustNowLocal = dateadd(ss,25    @CurrentUTCOffset,26    @JustNow)27  IF @FrequencyType IN('Day',28  'Week',29  'Month',30  'Year') OR @FrequencyType LIKE 'WD[_]__'31  BEGIN32    IF @StartTime = 'LB:ST'33    BEGIN34      INSERT INTO @starttimes_intern(Parameter1)35      SELECT CASE x.MyOffsetMinutes36      WHEN 1440 THEN37      '23:59'38      ELSE CONCAT(dbo.QBM_FCVStringPadLeft(dbo.QBM_FCVIntToString(x.MyOffsetMinutes / 60), 2, '0'),39      ':',40      dbo.QBM_FCVStringPadLeft(dbo.QBM_FCVIntToString(x.MyOffsetMinutes % 60), 2, '0'))41      END AS StartTime42      FROM(43      SELECT44        convert(int, isnull(sum(MinutesAvailable), 0)) AS MyOffsetMinutes45      FROM(46      SELECT47        e.dbid, e.name, e.SizePerDB, e.SizePerDB / a.SizeOverAll AS percentOfSize, 24.0 * 60.0 *(e.SizePerDB / a.SizeOverAll) AS MinutesAvailable48      FROM(49      SELECT50        d.dbid, d.name, convert(float, sum(f.size)) AS SizePerDB51      FROM sys.sysdatabases d52      JOIN sys.master_files f53        ON f.database_id = d.dbid54      WHERE55        d.name NOT IN('master', 'tempdb', 'model', 'msdb')56      GROUP BY d.dbid, d.name) AS e CROSS57      JOIN(58      SELECT59        convert(float, sum(f.size)) AS SizeOverAll60      FROM sys.sysdatabases d61      JOIN sys.master_files f62        ON f.database_id = d.dbid63      WHERE64        d.name NOT IN('master', 'tempdb', 'model', 'msdb')) AS a) AS parts65      WHERE66        parts.dbid < db_id()) AS x67    END68    ELSE69    BEGIN70      INSERT INTO @starttimes_intern(Parameter1)71      SELECT s.ParameterValue72      FROM QBM_FCVStringToList(@StartTime,73      char(7),74      1,75      0) s76      WHERE77        dbo.QBM_FGITimeIsValid(s.ParameterValue) = 178      IF @@ROWCOUNT = 079      BEGIN80        INSERT INTO @starttimes_intern(Parameter1)81        SELECT '23:59'82      END83    END84  END85  SELECT @lastrun_intern = @lastrun86  IF isnull(@lastrun_intern,87  N '1899-12-30') < N '1900-01-01'88  BEGIN89    SELECT90      @lastrun_intern = convert(datetime,91      N '1900-01-01',92      121)93  END94  SELECT @oldnextrun_intern = @oldnextrun95  IF isnull(@oldnextrun_intern,96  N '1899-12-30') < N '1900-01-01'97  BEGIN98    SELECT99      @oldnextrun_intern = convert(datetime,100      N '1900-01-01',101      121)102    SELECT103      @lastrun_intern = convert(datetime,104      N '1900-01-01',105      121)106  END107  IF @FrequencyType IN('Week',108  'Month',109  'Year')110  BEGIN111    SELECT @StartofPeriod = NULL112    SELECT113      TOP 1 @StartofPeriod = convert(datetime,114      MAX(isodate),115      121)116    FROM DialogCalendar117    WHERE118      CONVERT(datetime,119    isodate,120    121) <= @lastrun_intern AND(@FrequencyType = 'Week' AND isWeek = 1 OR @FrequencyType = 'Month' AND isMonth = 1 OR @FrequencyType = 'Year' AND121    isYear = 1)122    IF @StartofPeriod IS NULL123    BEGIN124      SELECT125        TOP 1 @StartofPeriod = convert(datetime,126        MAX(isodate),127        121)128      FROM DialogCalendar129      WHERE130        CONVERT(datetime,131      isodate,132      121) <= @JustNowLocal AND(@FrequencyType = 'Week' AND isWeek = 1 OR @FrequencyType = 'Month' AND isMonth = 1 OR @FrequencyType = 'Year' AND isYear133      = 1)134    END135    IF @FrequencyType = 'Week'136    BEGIN137      SELECT138        @StartofNextPeriod = DATEADD(wk,139        @frequency,140        @StartofPeriod)141    END142    IF @FrequencyType = 'Month'143    BEGIN144      SELECT145        @StartofNextPeriod = DATEADD(mm,146        @frequency,147        @StartofPeriod)148    END149    IF @FrequencyType = 'Year'150    BEGIN151      SELECT152        @StartofNextPeriod = DATEADD(yy,153        @frequency,154        @StartofPeriod)155    END156  END157  IF @FrequencyType LIKE 'WD[_]__'158  BEGIN159    SELECT @StartofPeriod = NULL160    SELECT161      TOP 1 @StartofPeriod = convert(datetime,162      MAX(c.IsoDate),163      121)164    FROM DialogCalendar c165    WHERE166      CONVERT(datetime,167    c.IsoDate,168    121) <= @lastrun_intern AND c.isMonth = 1169    IF @StartofPeriod IS NULL170    BEGIN171      SELECT172        TOP 1 @StartofPeriod = convert(datetime,173        MAX(isodate),174        121)175      FROM DialogCalendar176      WHERE177        CONVERT(datetime,178      isodate,179      121) <= @JustNowLocal AND isMonth = 1180    END181    SELECT @Wochentag = CASE @FrequencyType182    WHEN 'WD_Mo' THEN183    'Monday'184    WHEN 'WD_Tu' THEN185    'Tuesday'186    WHEN 'WD_We' THEN187    'Wednesday'188    WHEN 'WD_Th' THEN189    'Thursday'190    WHEN 'WD_Fr' THEN191    'Friday'192    WHEN 'WD_Sa' THEN193    'Saturday'194    WHEN 'WD_Su' THEN195    'Sunday'196    ELSE ''197    END198  END199  SELECT @nextrun = @oldnextrun_intern200  IF @FrequencyType IN('Week',201  'Year')202  BEGIN203    SELECT204      TOP 1 @nextrun = min(convert(datetime, c.IsoDate + ' ' + st.Parameter1, 121))205    FROM DialogCalendar c,206    (207    SELECT208      dbo.QBM_FCVStringToInt(mvp.parameterValue, 0) -1 AS Fsubtype209    FROM dbo.QBM_FCVStringToList(@Frequencysubtype, nchar(7), 0, 0) mvp) AS Fsubtypes,210    @starttimes_intern st211    WHERE212      (DATEADD(dd, Fsubtypes.Fsubtype, @StartofPeriod) = CONVERT(datetime, c.IsoDate, 121) OR DATEADD(dd,213    Fsubtypes.Fsubtype, @StartofNextPeriod) = CONVERT(datetime, c.IsoDate, 121)) AND(convert(datetime, c.IsoDate + ' ' + st.Parameter1,214    121) > @JustNowLocal AND @StartTime <> 'LB:ST' OR convert(datetime, c.IsoDate, 121) > @JustNowLocal AND @StartTime = 'LB:ST') AND @oldnextrun_intern215    <= @JustNowLocal216  END217  IF @FrequencyType LIKE 'WD[_]__'218  BEGIN219    SELECT220      TOP 1 @nextrun = min(convert(datetime, x.IsoDate + ' ' + st.Parameter1, 121))221    FROM(222    SELECT223      c.IsoDate,224      c.CalendarYear,225      c.CalendarMonth,226      c.CalendarDay,227      c.DayOfWeek,228      row_number() over(partition BY c.CalendarYear, c.CalendarMonth229    ORDER BY c.CalendarDay) AS nter,230    COUNT(*) over(partition BY c.CalendarYear, c.CalendarMonth) AS letzter231    FROM DialogCalendar c232    WHERE233      c.DayOfWeek = @Wochentag AND c.IsoDate >= @StartofPeriod AND(isnull(@FrequencySubType, '') = '' OR c.CalendarMonth IN(234    SELECT235      dbo.QBM_FCVStringToInt(mvp.ParameterValue, 0) AS monat236    FROM dbo.QBM_FCVStringToList(@Frequencysubtype, nchar(7), 0, 0) mvp))) AS x CROSS237    JOIN @starttimes_intern st238    WHERE239      (@Frequency > 0 AND x.nter = @Frequency OR @Frequency < 0 AND x.nter = x.letzter + @Frequency + 1) AND convert(datetime,240    x.IsoDate + ' ' + st.Parameter1,241    121) > @JustNowLocal AND @oldnextrun_intern <= @JustNowLocal242  END243  IF @FrequencyType IN('Month')244  BEGIN245    SELECT246      TOP 1 @nextrun = min(convert(datetime, c.IsoDate + ' ' + st.Parameter1, 121))247    FROM DialogCalendar c,248    (249    SELECT250      dbo.QBM_FCVStringToInt(mvp.parameterValue, 0) -1 AS Fsubtype251    FROM dbo.QBM_FCVStringToList(@Frequencysubtype, nchar(7), 0, 0) mvp) AS Fsubtypes,252    @starttimes_intern st253    WHERE254      (CONVERT(datetime, c.IsoDate, 121) = CASE255    WHEN month(DATEADD(dd, Fsubtypes.Fsubtype, @StartofPeriod)) = month(@StartofPeriod) THEN256    DATEADD(dd, Fsubtypes.Fsubtype, @StartofPeriod)257    WHEN month(DATEADD(dd, Fsubtypes.Fsubtype-1, @StartofPeriod)) = month(@StartofPeriod) THEN258    DATEADD(dd, Fsubtypes.Fsubtype-1, @StartofPeriod)259    WHEN month(DATEADD(dd, Fsubtypes.Fsubtype-2, @StartofPeriod)) = month(@StartofPeriod) THEN260    DATEADD(dd, Fsubtypes.Fsubtype-2, @StartofPeriod)261    ELSE DATEADD(dd, Fsubtypes.Fsubtype-3, @StartofPeriod)262    END OR CONVERT(datetime, c.IsoDate, 121) = CASE263    WHEN month(DATEADD(dd, Fsubtypes.Fsubtype, @StartofNextPeriod)) = month(@StartofNextPeriod) THEN264    DATEADD(dd, Fsubtypes.Fsubtype, @StartofNextPeriod)265    WHEN month(DATEADD(dd, Fsubtypes.Fsubtype-1, @StartofNextPeriod)) = month(@StartofNextPeriod) THEN266    DATEADD(dd, Fsubtypes.Fsubtype-1, @StartofNextPeriod)267    WHEN month(DATEADD(dd, Fsubtypes.Fsubtype-2, @StartofNextPeriod)) = month(@StartofNextPeriod) THEN268    DATEADD(dd, Fsubtypes.Fsubtype-2, @StartofNextPeriod)269    ELSE DATEADD(dd, Fsubtypes.Fsubtype-3, @StartofNextPeriod)270    END) AND(convert(datetime, c.IsoDate + ' ' + st.Parameter1, 121) > @JustNowLocal AND @StartTime <> 'LB:ST' OR convert(datetime,271    c.IsoDate, 121) > @JustNowLocal AND @StartTime = 'LB:ST') AND @oldnextrun_intern <= @JustNowLocal272  END273  IF @FrequencyType = 'Day'274  BEGIN275    SELECT TOP 1 @nextrun = x.datum276    FROM(277    SELECT278      convert(datetime, min(c.IsoDate + ' ' + st.Parameter1), 121) AS datum279    FROM DialogCalendar c,280    @starttimes_intern st281    WHERE282      ((convert(datetime, c.IsoDate + ' ' + st.Parameter1, 121) > @JustNowLocal AND datediff(d, convert(datetime,283    c.IsoDate, 121), convert(datetime, @JustNowLocal, 121)) = 0) OR datediff(d, @justnowlocal, convert(datetime,284    c.IsoDate + ' ' + st.Parameter1, 121)) >= @Frequency)) AS x285    WHERE286      @oldnextrun_intern <= @JustNowLocal287  END288  IF @FrequencyType = 'Hour'289  BEGIN290    SELECT291      TOP 1 @nextrun = dateadd(hh,292      @Frequency,293      @lastrun_intern)294    WHERE295      @oldnextrun_intern <= @JustNowLocal296    SELECT297      TOP 1 @nextrun = dateadd(hh,298      @Frequency,299      @JustNowLocal)300    WHERE301      @nextrun < @JustNowLocal302  END303  IF @FrequencyType = 'Min'304  BEGIN305    SELECT306      TOP 1 @nextrun = dateadd(mi,307      @Frequency,308      @lastrun_intern)309    WHERE310      @oldnextrun_intern <= @JustNowLocal311    SELECT312      TOP 1 @nextrun = dateadd(mi,313      @Frequency,314      @JustNowLocal)315    WHERE316      @nextrun < @JustNowLocal317  END318  SELECT319    @nextrun = convert(datetime,320    convert(nvarchar(16), @nextrun, 121),321    121)322  IF323  RIGHT(convert(nvarchar(16), @nextrun, 121),324  5) = N '00:00'325  BEGIN326    SELECT327      @nextrun = dateadd(ms,328      3,329      @nextrun)330  END331  ende:332  RETURN(@nextrun)333END
Open raw exported source
SQL ยท Raw59 lines
1        create   function dbo.QBM_FGIScheduleNextRun (@oldnextrun datetime, @lastrun datetime,  @JustNow datetime,  @StartTime varchar(256),  @FrequencyType2 nvarchar(16)  , @Frequency int , @FrequencySubType nvarchar(256) , @CurrentUTCOffset int  ) returns datetime as begin  declare @nextrun datetime  declare3 @starttimes_intern QBM_YParameterlist declare @lastrun_intern datetime declare @oldnextrun_intern datetime declare @Abends nvarchar(16) declare @JustNowLocal4 datetime declare @StartofPeriod datetime declare @StartofNextPeriod datetime declare @Wochentag varchar(16) select @Abends = N' 23:59:59.999' select @JustNowLocal5 = dateadd(ss, @CurrentUTCOffset, @JustNow) if @FrequencyType in ('Day', 'Week', 'Month', 'Year') or @FrequencyType like 'WD[_]__' begin if @StartTime 6= 'LB:ST' begin  insert into @starttimes_intern(Parameter1) select case x.MyOffsetMinutes when 1440 then '23:59' else concat(dbo.QBM_FCVStringPadLeft( 7dbo.QBM_FCVIntToString( x.MyOffsetMinutes / 60) , 2, '0') , ':' , dbo.QBM_FCVStringPadLeft( dbo.QBM_FCVIntToString(x.MyOffsetMinutes % 60), 2, '0') ) end8 as StartTime from ( select convert(int, isnull(sum(MinutesAvailable), 0)) as MyOffsetMinutes from ( select e.dbid, e.name, e.SizePerDB, e.SizePerDB / 9a.SizeOverAll as percentOfSize, 24.0 * 60.0 * (e.SizePerDB / a.SizeOverAll) as MinutesAvailable from ( select d.dbid, d.name,  convert(float, sum(f.size10)) as SizePerDB  from sys.sysdatabases d join sys.master_files f on f.database_id = d.dbid where d.name not in ('master', 'tempdb', 'model', 'msdb') group11 by d.dbid, d.name ) as e cross join ( select convert(float, sum(f.size)) as SizeOverAll from sys.sysdatabases d join sys.master_files f on f.database_id12 = d.dbid where d.name not in ('master', 'tempdb', 'model', 'msdb') ) as a ) as parts where parts.dbid < db_id() ) as x end else  begin insert into @starttimes_intern13(Parameter1) select s.ParameterValue from QBM_FCVStringToList(@StartTime, char(7), 1, 0) s where dbo.QBM_FGITimeIsValid(s.ParameterValue) = 1 if @@ROWCOUNT14 = 0 begin insert into @starttimes_intern(Parameter1) select '23:59' end end  end select @lastrun_intern = @lastrun if isnull(@lastrun_intern , N'1899-12-30'15) < N'1900-01-01' begin select @lastrun_intern = convert(datetime, N'1900-01-01', 121) end select @oldnextrun_intern = @oldnextrun if isnull(@oldnextrun_intern16 , N'1899-12-30') < N'1900-01-01' begin select @oldnextrun_intern = convert(datetime, N'1900-01-01', 121)  select @lastrun_intern = convert(datetime, N'1900-01-01'17, 121) end if @FrequencyType in ('Week', 'Month', 'Year') begin select @StartofPeriod = null select top 1 @StartofPeriod = convert(datetime, MAX(isodate18), 121) from DialogCalendar where CONVERT(datetime, isodate, 121) <= @lastrun_intern and ( @FrequencyType = 'Week' and isWeek = 1 or @FrequencyType = 'Month'19 and isMonth = 1 or @FrequencyType = 'Year' and isYear = 1 )   if @StartofPeriod is null begin select top 1 @StartofPeriod = convert(datetime, MAX(isodate20), 121) from DialogCalendar where CONVERT(datetime, isodate, 121) <= @JustNowLocal and ( @FrequencyType = 'Week' and isWeek = 1 or @FrequencyType = 'Month'21 and isMonth = 1 or @FrequencyType = 'Year' and isYear = 1 ) end if @FrequencyType = 'Week' begin select @StartofNextPeriod = DATEADD(wk, @frequency, @StartofPeriod22) end if @FrequencyType = 'Month' begin select @StartofNextPeriod = DATEADD(mm, @frequency, @StartofPeriod) end if @FrequencyType = 'Year' begin select23 @StartofNextPeriod = DATEADD(yy, @frequency, @StartofPeriod) end end if @FrequencyType like 'WD[_]__' begin  select @StartofPeriod = null select top 124 @StartofPeriod = convert(datetime, MAX(c.IsoDate), 121) from DialogCalendar c where CONVERT(datetime, c.IsoDate, 121) <= @lastrun_intern and c.isMonth25 = 1 if @StartofPeriod is null begin select top 1 @StartofPeriod = convert(datetime, MAX(isodate), 121) from DialogCalendar where CONVERT(datetime, isodate26, 121) <= @JustNowLocal and isMonth = 1 end select @Wochentag = case @FrequencyType when 'WD_Mo' then 'Monday' when 'WD_Tu' then 'Tuesday' when 'WD_We'27 then 'Wednesday' when 'WD_Th' then 'Thursday' when 'WD_Fr' then 'Friday' when 'WD_Sa' then 'Saturday' when 'WD_Su' then 'Sunday' else '' end end select28 @nextrun = @oldnextrun_intern    if @FrequencyType in ('Week', 'Year') begin  select top 1 @nextrun = min(convert(datetime, c.IsoDate + ' ' + st.Parameter129 , 121)) from DialogCalendar c, (select dbo.QBM_FCVStringToInt(mvp.parameterValue , 0) -1  as Fsubtype from dbo.QBM_FCVStringToList(@Frequencysubtype ,30 nchar(7), 0, 0 ) mvp ) as Fsubtypes , @starttimes_intern st where (DATEADD(dd, Fsubtypes.Fsubtype, @StartofPeriod) = CONVERT(datetime, c.IsoDate, 121)31  or DATEADD(dd, Fsubtypes.Fsubtype, @StartofNextPeriod) = CONVERT(datetime, c.IsoDate, 121) ) and (convert(datetime, c.IsoDate + ' ' + st.Parameter1 ,32 121) > @JustNowLocal and @StartTime <> 'LB:ST'  or convert(datetime, c.IsoDate , 121) > @JustNowLocal and @StartTime = 'LB:ST' ) and @oldnextrun_intern33 <= @JustNowLocal  end if @FrequencyType like 'WD[_]__' begin select top 1 @nextrun = min(convert(datetime, x.IsoDate + ' ' + st.Parameter1 , 121)) from34 ( select c.IsoDate, c.CalendarYear, c.CalendarMonth, c.CalendarDay, c.DayOfWeek , row_number() over (partition by c.CalendarYear, c.CalendarMonth order35 by c.CalendarDay) as nter , COUNT(*) over (partition by c.CalendarYear, c.CalendarMonth ) as letzter from DialogCalendar c where c.DayOfWeek = @Wochentag36 and c.IsoDate >= @StartofPeriod and ( isnull(@FrequencySubType, '') = '' or c.CalendarMonth in (select dbo.QBM_FCVStringToInt(mvp.ParameterValue, 0) as37 monat from dbo.QBM_FCVStringToList(@Frequencysubtype , nchar(7), 0, 0 ) mvp ) ) ) as x cross join @starttimes_intern st where (@Frequency > 0 and x.nter38 = @Frequency or @Frequency < 0 and x.nter = x.letzter + @Frequency + 1 ) and convert(datetime, x.IsoDate + ' ' + st.Parameter1 , 121) > @JustNowLocal 39and @oldnextrun_intern <= @JustNowLocal end if @FrequencyType in ('Month')  begin  select top 1 @nextrun = min(convert(datetime, c.IsoDate + ' ' + st.Parameter140 , 121)) from DialogCalendar c, (select dbo.QBM_FCVStringToInt(mvp.parameterValue , 0) -1  as Fsubtype from dbo.QBM_FCVStringToList(@Frequencysubtype ,41 nchar(7), 0, 0 ) mvp ) as Fsubtypes , @starttimes_intern st where ( CONVERT(datetime, c.IsoDate, 121) = case when month(DATEADD(dd, Fsubtypes.Fsubtype42, @StartofPeriod)) = month(@StartofPeriod) then DATEADD(dd, Fsubtypes.Fsubtype, @StartofPeriod) when month(DATEADD(dd, Fsubtypes.Fsubtype-1, @StartofPeriod43)) = month(@StartofPeriod) then DATEADD(dd, Fsubtypes.Fsubtype-1, @StartofPeriod) when month(DATEADD(dd, Fsubtypes.Fsubtype-2, @StartofPeriod)) = month44(@StartofPeriod) then DATEADD(dd, Fsubtypes.Fsubtype-2, @StartofPeriod) else DATEADD(dd, Fsubtypes.Fsubtype-3, @StartofPeriod)  end  or CONVERT(datetime45, c.IsoDate, 121) = case when month(DATEADD(dd, Fsubtypes.Fsubtype, @StartofNextPeriod)) = month(@StartofNextPeriod) then DATEADD(dd, Fsubtypes.Fsubtype46, @StartofNextPeriod) when month(DATEADD(dd, Fsubtypes.Fsubtype-1, @StartofNextPeriod)) = month(@StartofNextPeriod) then DATEADD(dd, Fsubtypes.Fsubtype-147, @StartofNextPeriod) when month(DATEADD(dd, Fsubtypes.Fsubtype-2, @StartofNextPeriod)) = month(@StartofNextPeriod) then DATEADD(dd, Fsubtypes.Fsubtype-248, @StartofNextPeriod) else DATEADD(dd, Fsubtypes.Fsubtype-3, @StartofNextPeriod)  end ) and (convert(datetime, c.IsoDate + ' ' + st.Parameter1 , 121) >49 @JustNowLocal and @StartTime <> 'LB:ST'  or convert(datetime, c.IsoDate , 121) > @JustNowLocal and @StartTime = 'LB:ST' ) and @oldnextrun_intern <= @JustNowLocal50 end if @FrequencyType = 'Day' begin select top 1 @nextrun = x.datum from (select convert(datetime, min(c.IsoDate + ' ' + st.Parameter1), 121) as datum51 from DialogCalendar c , @starttimes_intern st where ( ( convert(datetime, c.IsoDate + ' ' + st.Parameter1, 121) > @JustNowLocal  and datediff(d, convert52(datetime, c.IsoDate, 121), convert(datetime, @JustNowLocal, 121)) = 0 )  or datediff(d, @justnowlocal, convert(datetime, c.IsoDate + ' ' + st.Parameter153, 121)) >= @Frequency ) ) as x where @oldnextrun_intern <= @JustNowLocal end if @FrequencyType = 'Hour' begin  select top 1 @nextrun = dateadd(hh, @Frequency54, @lastrun_intern) where @oldnextrun_intern <= @JustNowLocal  select top 1 @nextrun = dateadd(hh, @Frequency, @JustNowLocal) where @nextrun < @JustNowLocal55 end if @FrequencyType = 'Min' begin  select top 1 @nextrun = dateadd(mi, @Frequency, @lastrun_intern) where @oldnextrun_intern <= @JustNowLocal  select56 top 1 @nextrun = dateadd(mi, @Frequency, @JustNowLocal) where @nextrun < @JustNowLocal end  select @nextrun = convert(datetime, convert(nvarchar(16), 57@nextrun, 121), 121) if right(convert(nvarchar(16), @nextrun, 121), 5) = N'00:00' begin  select @nextrun = dateadd(ms, 3, @nextrun) end ende: return (@nextrun58) end 59