Where to put custom function at?
Let's say I make a custom function, do I make it a CFC or a tag?
Here is some sample code (I put in bold my function call)
<cfif IsDefined("form.submit")>
<cfset data.comment = Trim(HTMLEditFormat(form.comment))>
<cfset data.name = Trim(REReplace(form.name, "[^A-Za-z0-9 ]", "", "all"))>
<cfset data.location = Trim(CustomFunction(form.location))><!--- where to put it? as cfc or as a tag? --->
<cfif data.comment NEQ "">
<cfif data.name EQ "">
<cfset data.name = "Anonymous">
</cfif>
<cfinvoke
component="guestbook.cfc.db"
method="insert_comment">
<cfinvokeargument name="form_data" value="#data#"/>
</cfinvoke>
<cfelse>
<cfset message="Comment is required!">
</cfif>
</cfif>
Custom tags are different than udfs. Let's stick with udfs. Your location choices are:
1. If only one template is going to use it, you can put it in that template. Otherwise,
2. You can put it in a .cfm file and cfinclude that file whenever you want to call the function, or
3. You can put it into a .cfc.
A little while back, someone ran some tests and posted the results on one of these forums. The gist of it was that Option 2 would run faster than Option 3.
Similar Messages
-
Where to put a function to perform only once?
Question #1: I am writing an applet, and as part of it I have created a custom canvas class which extends the canvas class... When this is created I would like to perform a custom calculation of the size that it should be. Where is the best place to put this function? Right now I have put it in getPreferredSize(), but I'm afraid it might be called everytime i scroll or resize or whatever?
Question #2: When I load my IE browser and go to the page with my applet, then call the applet.getSize() function it works. When I hit the refresh button on IE, getSize returns 0. Is there a workaround to this? I have the getSize() in the init of the applet...
Thank you!
RustyHi
About #1 question, the best place is at constructor class, "once a time" right? but getPreferredSize really is called so many time as needed, you know the reason. The simple workaround for #2 question is to store applet dimension at the very first call, also at applet construction.
Regards. -
Where to put custom .jar-files in order to use them in scripting QPAC?
Hi,
For testing purposes, I wrote a simple class and put it in a .jar-file to use in scripting QPAC. Unfortunately, I get the following error message in JBOSS:
Class: FooBar not found in namespace
Where do I have to put custom library (jar-)files in order for JBOSS to find them? I already tried
[...]\jboss\lib as well as
[...]\jboss\server\all\lib.
Regards,
SteveHi Steve
You need to put them in two places:
1. In the server classpath, so that they can be found at runtime. jboss\server\all\lib should work, or you can even drop them into the server/all/deploy directory. I think if you put them in the lib directory, you need to restart Jboss, whereas if you put them in the deploy directory, they should be dynamically picked up.
2. For testing purposes, the extra jars need to be in the classpath of the Workflow Designer. Please download our SQLPlus QPAC from:
http://www.avoka.com/avoka/qpac_library.shtml
It includes a document that describes a technique for adding extra jars to the classpath.
Regards,
Howard
http://www.avoka.com -
Where is the best place to put custom functions?
Hi,
I have a composition which has a number of symbols. I have to call some custom methods externally and was wondering where is the best place to put the custom methods?
I have seen posts that I should put the code in the CompositionReady event of the stage but I would like to put it a bit closer to the symbol.
Is this the best place?
Sham.Here is a case:
It's a good idea if you well understand global and local variables.
About complete event, you are right. -
Where to put initialization functions?
Where should I put functions that are to only run once when
the flash is initially loaded and never again? Previously I have
put it in the first frames onEnterFrame() and then used stop(); so
the frames don't play, but what if I want the frame to play? I've
tried using a global boolean variable but this doesn't seem to work
either. Any ideas?
Thanks.Also, I think you have misunderstood the purpose of
onEnterFrame(). It is poorly named and doesn't mean when you enter
the frame.
What it really means is to do something repeatedly at the
frame rate – even if the timeline is stopped.
So:
this.onEnterFrame=function(){
myInitialVariable=10;
Means it will set the variable 20 or 30 times each second (or
whatever your frame rate is) until you tell it: delete
this.onEnterframe.
Other than that, the best thing to do would be to read all
the entries in the help file for the MovieClip class. There you
will find the lovely onLoad event. Make a new movie with maybe 10
frames and put this code in the first frame. Then test it and
watch.
this.onLoad=function(){
trace("hello world");
trace("How are ya"); -
Where to put custom taglib descriptor
Should the custom tag library descriptor file go in $CATALINA_HOME/webappname/WEB-INF? Or should it go in $CATALINA_HOME/webappname/? (with the rest of the JSPs)
Thanks.Ah, thanks. (Malcolm:)I thought it would work anywhere, but good practice seems to suggest that the webapp-specific descriptor files go in WEB-INF and (Norman:) thanks for confirming that. (I didn't know about the tld directory though, which makes sense for organizing large numbers of custom tags.)
-
templates?
you can't add as2 support to flash cc without a major effort.
however, you can add other flash player support to flash cc without much problem: http://forums.adobe.com/thread/1235145?tstart=0 -
Why does Discoverer put my custom function into GROUP BY
To make things clear with simple example:
I have 10 id's from people (people.id) and sum function on their salary [sum(people.salary)] during a period of time that i set in my parameters.
The sql looks something like this:
SELECT PEOPLE.ID
,SUM(PEOPLE.SALARY)
FROM FRS_PEOPLE
WHERE [MY CONDITIONS]
GROUP BY PEOPLE.ID
I registered a function that uses people.id, and some other parameters to calculate something for each people.id!
I made a calculation:
MY_FUNCTION(people.id,'xxx','yyy')
,so my sql looks like this now:
SELECT PEOPLE.ID
,SUM(PEOPLE.SALARY)
,MY_FUNCTION(people.id,':xxx',':yyy')
FROM FRS_PEOPLE
WHERE [MY CONDITIONS]
GROUP BY PEOPLE.ID,MY_FUNCTION(people.id,':xxx',':yyy')
It runs but never finishes....?!
When i run my sql in sqlplus i do not put my function into group by, but discoverer does so, despite it already has people.id item in GROUP BY!
And if i put instead of people.id an actual id it works correctly and does not put my function into group by!
The sql i am looking for and works correctly is:
SELECT PEOPLE.ID
,SUM(PEOPLE.SALARY)
,MY_FUNCTION(people.id,'xxx','yyy')
FROM FRS_PEOPLE
WHERE [MY CONDITIONS]
GROUP BY PEOPLE.ID
Please someone help!
My select clause is much more complicated, with many outer joins so i made the above up just to explain to you what my problem is!
I hope i made my self clear!
Help would be very appreciated.Hi,
I think there is a problem with your function. That fact that the report completes when an actual id is used must not when a people.id is used suggests that it works when the function is called once with an actual id but not when it is called many times with a people.id.
If the function is doing complex lookups and calculations to obtain a salary for each people.id then often this type of report will run quicker with the salary calculation is brought into the report SQL using joins etc.
Tracing the Discoverer session running the report will show you all the SQL processed by the database and the execution plans used. It will show you how often the function is being called and what SQL is being run by the function.
Rod West -
Where to put my customized formatting that Control Hints does not provide?
To whom that know or have experience with it:
The control hints does not provide solutions for all possible formatting needs. For example, I need to display only last four digits of social security numbers (i.e., for "123-45-6789", display "***-**-6789"). Another data table column stores school semesters as YYYYMM, e.g., 200902, where 2009 is the year and 02 is the month that represents Spring (MM can also be 06 and 09 that represent Summer and Fall). I need to display the semester in a more user-friendly way (i.e., for "200902", display "Spring 2009"). Of course, I can not change data format in the table; I only seek to format the display of the data.
I would think that it takes only a few lines of java code to do these formatting by splitting the string into sub-strings, replace some of them with appropriate new values, then re-assemble them. But where to put such code? Does any documentation cover this topic?
NewmanShay,
I read the document, tried it, and it worked out nicely.
There is not the getAttributeName() method in the ViewObjectImpl class in version 10.1.3.4, which is the version I am using. But the EO class has it and it works out all the same.
I don't know how long it would otherwise take me to read and fumble to find out where to put the custom formatting code. Your experience and familiarity with the technology really saved me a huge amount of time. Thank you so much for your help!
Newman -
Architecture question...where to put the code
Newbie here, so please be gentle and explicit (no detail is
too much to give or insulting to me).
I'm hoping one of you architecture/design gurus can help me
with this. I am trying to use good principals of design and not
have code scattered all over the place and also use OO as much as
possible. Therefore I would appreciate very much some advice on
best practices/good design for the following situation.
On my main timeline I have a frame where I instantiate all my
objects. These objects refer to movieClips and textFields etc. that
are on a content frame on that timeline. I have all the
instantiation code in a function called initialize() which I call
from the content frame. All this works just fine. One of the
objects on the content frame is a movieClip which I allow the user
to go forward and backward in using some navigation controls.
Again, the object that manages all that is instantiated on the main
timeline in the initialize() function and works fine too. So here's
my question. I would like to add some interactive objects on some
of the frames of the movieClip I allow the user to navigate forward
and backward in (lets call it NavClip) . For example on frame 1 I
might have a button, on frame 2 and 3 nothing, on frame 4 maybe a
clip I allow the user to drag around etc. So I thought I would add
a layer to NavClip where I will have key frames and put the various
interactive assets on the appropriate key frames. So now I don't
know where to put the code that instantiates these objects (i.e.
the objects that know how to deal with the events and such for each
of these interactive assets). I tried putting the code on my main
timeline, but realized that I can't address the interactive assets
until the NavClip is on the frame that holds the particular asset.
I'm trying not to sprinkle code all over the place, so what do I
do? I thought I might be able to address the assets by just
providing a name for the asset and not a reference to the asset
itself, and then address the asset that way (i.e.
NavClip["interactive_mc"] instead of NavClip.interactive_mc), but
then I thought that's not good since I think there is no type
checking when you use the NavClip["interactive_mc"] form.
I hope I'm not being too dim a bulb on this and have missed
something really obvious. Thanks in advance to anyone who can help
me use a best practice.1. First of all, the code should be:
var myDraggable:Draggable=new Draggable(myClip_mc);
myDraggable.initDrag();
Where initDrag() is defined in the Draggable class. When you
start coding functions on the timeline... that's asking for
problems.
>>Do I wind up with another object each time this
function is called
Well, no, but. That would totally depend on the code in the
(Draggable) class. Let's say you would have a private static var
counter (private static, so a class property instead of an instance
property) and you would increment that counter using a
setInterval(). The second time you enter the frame and create a new
Draggable object... the counter starts at the last value of the
'old' object. So, you don't get another object with your function
literal but you still end up with a faulty program. And the same
goes for listener objects that are not removed, tweens that are
running and so on.
The destroy() method in a custom class (=object, I can't
stress that enough...) needs to do the cleanup, removing anything
you don't need anymore.
2. if myDraggable != undefined
You shouldn't be using that, period. If you don't need the
asset anymore, delete it using the destroy() method. Again, if you
want to make sure only one instance of a custom object is alive,
use the Singleton design pattern. To elaborate on inheritance:
define the Draggable class (class Draggable extends MovieClip) and
connect it to the myClip_mc using the linkage identifier in the
library). In the Draggable class you can define a function unOnLoad
(an event fired when myClip_mc is removed using
myClip_mc.removeMovieClip()...) and do the cleanup there.
3. A destroy() method performs a cleanup of any assets we
don't need anymore to make sure we don't end up with all kinds of
stuff hanging around in the memory. When you extend the MovieClip
Class you can (additionally) use the onUnLoad event. And with the
code you posted, no it wouldn't delete the myClip_mc unless you
program it to do so. -
Issue with calling custom function in merge command -10g
Hi,
I have ran into issue while calling a custom function in merge command.
It throws error 'Invalid identifier'. Oracle doesnt understand that it is a function and take the function name as column name.
Since no such collumn name exists, it throws 'Invalid identifier'.
Interestingly, merge command works fine when it has a oracle function (replace, decode).
The oracle version is 10.2.0.3
It is very urgent.
Any pointers will be helpful.
Regards,
RaviI don't have privileges to create dblink, but this is working for me.
So, i don't think function can be a issue here.
satyaki>
satyaki>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
Elapsed: 00:00:01.02
satyaki>
satyaki>
satyaki>create table hist_tab
2 as
3 select * from emp
4 where sal between 2000 and 4000;
Table created.
Elapsed: 00:00:00.09
satyaki>
satyaki>select * from hist_tab;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO JOB1 DOB
7844 TURNER SALESMAN 7698 08-SEP-81 2178 0 30 SALESMAN
Elapsed: 00:00:00.00
satyaki>
satyaki>
satyaki>update hist_tab
2 set mgr = 7794;
1 row updated.
Elapsed: 00:00:00.01
satyaki>
satyaki>commit;
Commit complete.
Elapsed: 00:00:00.00
satyaki>
satyaki>select * from hist_tab;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO JOB1 DOB
7844 TURNER SALESMAN 7794 08-SEP-81 2178 0 30 SALESMAN
Elapsed: 00:00:00.00
satyaki>
satyaki>
satyaki>
satyaki>
satyaki>create table tran_tab
2 as
3 select * from emp
4 where sal between 2000 and 7000;
Table created.
Elapsed: 00:00:00.00
satyaki>
satyaki>select * from tran_tab;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO JOB1 DOB
7844 TURNER SALESMAN 7698 08-SEP-81 2178 0 30 SALESMAN
7902 FORD ANALYST 7566 03-DEC-81 5270.76 20 ANALYST
Elapsed: 00:00:00.00
satyaki>
satyaki>ed
Wrote file afiedt.buf
1 create or replace function fun(c_in number)
2 return number
3 is
4 c_out number(4);
5 begin
6 if c_in < 7900 then
7 c_out := 0;
8 else
9 c_out := 1;
10 end if;
11 return c_out;
12* end;
13 /
Function created.
Elapsed: 00:00:01.00
satyaki>
satyaki>merge into hist_tab o
2 using (
3 select empno,
4 ename,
5 job,
6 mgr,
7 hiredate,
8 sal,
9 comm,
10 deptno,
11 job1,
12 dob
13 from (
14 select k.*,
15 rank() over(order by fun(k.empno)) rn
16 from tran_tab k
17 )
18 where rn = 1
19 ) n
20 on ( o.empno = n.empno)
21 when matched then
22 update set o.ename = n.ename,
23 o.job = n.job,
24 o.mgr = n.mgr,
25 o.hiredate = n.hiredate,
26 o.sal = n.sal,
27 o.comm = n.comm,
28 o.deptno = n.deptno,
29 o.job1 = n.job1,
30 o.dob = n.dob
31 when not matched then
32 insert(
33 o.empno,
34 o.ename,
35 o.job,
36 o.mgr,
37 o.hiredate,
38 o.sal,
39 o.comm,
40 o.deptno,
41 o.job1,
42 o.dob
43 )
44 values(
45 n.empno,
46 n.ename,
47 n.job,
48 n.mgr,
49 n.hiredate,
50 n.sal,
51 n.comm,
52 n.deptno,
53 n.job1,
54 n.dob
55 );
1 row merged.
Elapsed: 00:00:00.03
satyaki>
satyaki>select * from hist_tab;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO JOB1 DOB
7844 TURNER SALESMAN 7698 08-SEP-81 2178 0 30 SALESMAN
Elapsed: 00:00:00.00
satyaki>You can check the final output with old output. It is working perfectly - i guess.
Regards.
Satyaki De. -
Where to put javascript code?
Hello,
I am trying to set some columns in a list as "read-only" and is using the following code:
<script type=”text/javascript”>
function SetReadOnly()
var elements=document.getElementById(’4_ctl00_ctl00_TextField’);
elements.readOnly=true;
_spBodyOnLoadFunctionNames.push(“SetReadOnly()”);
</script>
But I am not sure where to put the code in. Should I put it in the space in Content Editor Web Part,
or through a link to a txt file, or in "Edit HTML"? I've tried them but none works.
Thanks a lot!
PatrickYou can try this:
1) Open your Sharepoint List. Go to List edit view.
2) On right side of Ribbon you will find "Form Web Parts" option as shown in figure.
3) Choose your List form which you want to edit.
4) Now you can add web part in new window.
5) Add Content Editor Web part.
6) In content editor web part add the path of your "txt" file in which you have written your script, for eg.
<!DOCTYPE html>
<html>
<body>
<script type=”text/javascript”>
function SetReadOnly()
var elements=document.getElementById('4_ctl00_ctl00_TextField');
elements.readOnly=true;
_spBodyOnLoadFunctionNames.push("SetReadOnly()");
</script>
</body>
</html>
I haven't tried this method so I am not sure but hope it works...:D
***If my post is answer for your query please mark as answer***
***If my answer is helpful please vote*** -
Why is there a limitation on the number of boolean parameters in a custom function?
We have a custom function which 'flattens' four text temporal values into a single temporal value.
We want to do the same with boolean temporal values.
However, OPM throws an error when it reads the metadata for the function in extensions.xml. It says all boolean paramaters need to be last. We can't put them all last as there are more than one.
This is OPM error code OPM-W00001.
Any ideas on how I can work around this limitation?Taken from OPA Developer's help:
Only one boolean parameter can be passed to a function, and it must be the last parameter. This is due to a limitation in the rule compiler. Any number of other parameters may be present however.
Should you want to pass more boolean values, create a temporary/document text variable with values "True"/"False" using rule table. -
Help on custom function...
Hi all
I'm having a problem with this custom function/report posted on TechNet while back for ConfigMgr 2007
http://social.technet.microsoft.com/wiki/contents/articles/7870.sccm-2007-create-report-of-upcoming-maintenance-windows-by-client.aspx
I've made the needed changes according to this blog post:
https://sccmfaq.wordpress.com/2013/08/22/sccm-2012-show-next-effective-maintenance-window/
..but when using maintenance windows that occurs for example 1st tuesday of every 1 months, the function returns the date week ahead. For example now (on 28th of Feb) next maintenance window should be on Tuesday March 3rd, but instead the report is showing
Tuesday March 10th.
Any help on modifying the function would be appreciated, I saw that there comments on the original post about the recurrence type 4 (monthly by weekday as noted here https://msdn.microsoft.com/en-us/library/cc143300.aspx) not working correctly in the function.
It seems that the function now returns the weekday of first full week of the month instead of the correct day.
The function is this:
CREATE FUNCTION [dbo].[SCCM_GetNextServiceWindow](@ScheduleToken AS CHAR(16), @RecurrenceType AS INT) RETURNS @NextServiceWindow TABLE (ScheduleToken CHAR(16), RecurrenceType INT, NextServiceWindow DATETIME, Duration INT, IsGMTTime BIT) AS BEGIN
--1 Occurs on 1/1/2012 12:00 AM 00011A8500080000
--2 Occurs every 3 day(s) effective 1/1/2012 8:00 PM 02811A8040100018
--3 Occurs every 3 week(s) on Saturday effective 1/1/2012 8:00 PM 02811A80401F6000
--3 Occurs every 1 week(s) on Saturday effective 1/1/2012 8:00 PM 02811A80401F2000
--5 Occurs day 2 of every 2 month(s) effective 1/1/2012 8:00 PM 02811A8040288800
--5 Occurs day 31 of every 1 month(s) effective 1/1/2012 8:00 PM 02811A80402FC400
--5 Occurs the last day of every 3 months effective 1/1/2012 8:00 PM 02811A8040280C00
--5 Occurs the last day of every 1 months effective 1/1/2012 8:00 PM 02811A8040280400
--4 Occurs the Third Monday of every 1 month(s) effective 1/1/2012 4:00 AM 00811A9E08221600
--4 Occurs the Last Wednesday of every 1 month(s) effective 1/1/2012 8:00 PM 02811A8040241000
--4 Occurs the Fourth Wednesday of every 1 month(s) effective 1/1/2012 8:00 PM 02811A8040241800
--4 Occurs the Last Monday of every 1 month(s) effective 1/1/2012 8:00 PM 02811A8040221000
--3 Occurs every 1 week(s) on Monday effective 1/1/2012 4:00 AM 00811A9E081A2000
-- http://msdn.microsoft.com/en-us/library/cc143300.aspx [This link is external to TechNet Wiki. It will open in a new window.]
DECLARE @RecurrenceType_NONE INT
, @RecurrenceType_DAILY INT
, @RecurrenceType_WEEKLY INT
, @RecurrenceType_MONTHLYBYWEEKDAY INT
, @RecurrenceType_MONTHLYBYDATE INT
SELECT @RecurrenceType_NONE = 1
, @RecurrenceType_DAILY = 2
, @RecurrenceType_WEEKLY = 3
, @RecurrenceType_MONTHLYBYWEEKDAY = 4
, @RecurrenceType_MONTHLYBYDATE = 5
-- http://msdn.microsoft.com/en-us/library/cc143505.aspx [This link is external to TechNet Wiki. It will open in a new window.]
--DECLARE @RecurrenceType INT; SET @RecurrenceType = @RecurrenceType_WEEKLY
--DECLARE @ScheduleToken CHAR(16); SET @ScheduleToken = '00811A9E081A2000'
DECLARE @ScheduleStartTime INT; SET @ScheduleStartTime = CAST(CONVERT(BINARY(4), LEFT(@ScheduleToken, 8), 2) AS INT)
DECLARE @ScheduleDuration INT; SET @ScheduleDuration = CAST(CONVERT(BINARY(4), RIGHT(@ScheduleToken, 8), 2) AS INT)
-- Duration is in minutes
DECLARE @Duration INT; SET @Duration = @ScheduleStartTime % POWER(2, 6)
-- Calculate the start time
DECLARE @StartTime DATETIME; SET @StartTime = CONVERT(DATETIME, '01/01/1970 00:00:00')
SET @StartTime = DATEADD(YEAR, (@ScheduleStartTime / POWER(2,6)) % POWER(2, 6), @StartTime)
SET @StartTime = DATEADD(MONTH, ((@ScheduleStartTime / POWER(2,12)) % POWER(2, 4)) - 1, @StartTime)
SET @StartTime = DATEADD(DAY, ((@ScheduleStartTime / POWER(2,16)) % POWER(2, 5)) - 1, @StartTime)
SET @StartTime = DATEADD(HOUR, (@ScheduleStartTime / POWER(2,21)) % POWER(2, 5), @StartTime)
SET @StartTime = DATEADD(MINUTE, (@ScheduleStartTime / POWER(2,26)) % POWER(2, 5), @StartTime)
-- Determinte UTC and Flags
DECLARE @IsGMTTime BIT; SET @IsGMTTime = CAST(@ScheduleDuration % POWER(2, 1) AS BIT)
DECLARE @Flags INT; SET @Flags = (@ScheduleDuration / POWER(2,19)) % POWER(2, 3)
-- Calculate the total duration in minutes
SET @Duration = @Duration + ((@ScheduleDuration / POWER(2,22)) % POWER(2, 5)) * 24 * 60 -- DAYS
SET @Duration = @Duration + ((@ScheduleDuration / POWER(2,27)) % POWER(2, 5)) * 60 -- HOURS
DECLARE @Now DATETIME
IF @IsGMTTime = 1 BEGIN
SET @Now = GETUTCDATE()
END ELSE BEGIN
SET @Now = GETDATE()
END
DECLARE @NextMaintenanceWindow DATETIME
IF @RecurrenceType = @RecurrenceType_NONE BEGIN
IF DATEADD(MINUTE, @Duration, @StartTime) > @Now BEGIN
SET @NextMaintenanceWindow = @StartTime
END
END ELSE IF @RecurrenceType = @RecurrenceType_DAILY BEGIN
IF DATEADD(MINUTE, @Duration, @StartTime) > @Now BEGIN
SET @NextMaintenanceWindow = @StartTime
END ELSE BEGIN
-- Calculate the daily interval in minutes
DECLARE @DailyInterval INT
SET @DailyInterval = ((@ScheduleDuration / POWER(2,3)) % POWER(2, 5)) * 24 * 60
SET @DailyInterval = @DailyInterval + ((@ScheduleDuration / POWER(2,8)) % POWER(2, 5)) * 60
SET @DailyInterval = @DailyInterval + (@ScheduleDuration / POWER(2,13)) % POWER(2, 6)
-- Calculate the total number of completed intervals
DECLARE @DailyNumberOfCompletedIntervals INT; SET @DailyNumberOfCompletedIntervals = ROUND(CAST(DATEDIFF(MINUTE, @StartTime, @Now) AS DECIMAL) / @DailyInterval, 0, 0)
-- Calculate the next interval
DECLARE @DailyNextInterval DATETIME; SET @DailyNextInterval = DATEADD(MINUTE, @DailyNumberOfCompletedIntervals * @DailyInterval, @StartTime)
-- Recalc the next interval if the next interval plus the expected duration is in the past
IF DATEADD(MINUTE, @Duration, @DailyNextInterval) < @Now BEGIN
SET @DailyNextInterval = DATEADD(MINUTE, (@DailyNumberOfCompletedIntervals + 1) * @DailyInterval, @StartTime)
END
SET @NextMaintenanceWindow = @DailyNextInterval
END
END ELSE IF @RecurrenceType = @RecurrenceType_WEEKLY BEGIN
DECLARE @WeeklyInterval INT; SET @WeeklyInterval = (@ScheduleDuration / POWER(2,13)) % POWER(2, 3)
DECLARE @WeeklyDoW INT; SET @WeeklyDoW = (@ScheduleDuration / POWER(2,16)) % POWER(2, 3)
-- Adjust the start time to match the next day of week that matches the interval
DECLARE @WeeklyStartTime DATETIME; SET @WeeklyStartTime = DATEADD(DAY, (7 - DATEPART(WEEKDAY, @StartTime) + @WeeklyDoW % 7), @StartTime)
IF DATEADD(MINUTE, @Duration, @WeeklyStartTime) > @Now BEGIN
SET @NextMaintenanceWindow = @WeeklyStartTime
END ELSE BEGIN
-- Calculate the total number of completed intervals
DECLARE @WeeklyNumberOfCompletedIntervals INT; SET @WeeklyNumberOfCompletedIntervals = ROUND(CAST(DATEDIFF(WEEK, @WeeklyStartTime, @Now) AS DECIMAL) / @WeeklyInterval, 0, 0)
-- Calculate the next interval
DECLARE @WeeklyNextInterval DATETIME; SET @WeeklyNextInterval = DATEADD(WEEK, @WeeklyNumberOfCompletedIntervals * @WeeklyInterval, @WeeklyStartTime)
-- Recalc the next interval if the next interval plus the expected duration is in the past
IF DATEADD(MINUTE, @Duration, @WeeklyNextInterval) < @Now BEGIN
SET @WeeklyNextInterval = DATEADD(WEEK, (@WeeklyNumberOfCompletedIntervals + 1) * @WeeklyInterval, @WeeklyStartTime)
END
SET @NextMaintenanceWindow = @WeeklyNextInterval
END
END ELSE IF @RecurrenceType = @RecurrenceType_MONTHLYBYWEEKDAY BEGIN
DECLARE @MonthlyBWWeek INT; SET @MonthlyBWWeek = (@ScheduleDuration / POWER(2,9)) % POWER(2, 3)
DECLARE @MontlhyBWInterval INT; SET @MontlhyBWInterval = (@ScheduleDuration / POWER(2,12)) % POWER(2, 4)
DECLARE @MonthlyBWDoW INT; SET @MonthlyBWDoW = (@ScheduleDuration / POWER(2,16)) % POWER(2, 3)
-- Calculate the total number of completed intervals
DECLARE @MonthlyBWNumberOfCompletedIntervals INT; SET @MonthlyBWNumberOfCompletedIntervals = ROUND(CAST(DATEDIFF(MONTH, @StartTime, @Now) AS DECIMAL) / @MontlhyBWInterval, 0, 0)
IF @MonthlyBWWeek = 0 BEGIN
-- Calculate the next interval
DECLARE @MonthlyBWLDOMNextInterval DATETIME; SET @MonthlyBWLDOMNextInterval = DATEADD(MONTH, @MonthlyBWNumberOfCompletedIntervals * @MontlhyBWInterval, @StartTime)
-- Calculate last day of month
SET @MonthlyBWLDOMNextInterval = DATEADD(DAY, DATEDIFF(DAY, @MonthlyBWLDOMNextInterval, DATEADD(DAY, -1, DATEADD(M, DATEDIFF(MONTH, 0, @MonthlyBWLDOMNextInterval) + 1, 0))), @MonthlyBWLDOMNextInterval)
-- Calculate the last day of the week for the month
SET @MonthlyBWLDOMNextInterval = DATEADD(DAY, -(7 - DATEPART(WEEKDAY, @MonthlyBWLDOMNextInterval) + @MonthlyBWDoW % 7), @MonthlyBWLDOMNextInterval)
IF DATEADD(MINUTE, @Duration, @MonthlyBWLDOMNextInterval) < @Now BEGIN
-- Recalc for the next month interval
SET @MonthlyBWLDOMNextInterval = DATEADD(MONTH, (@MonthlyBWNumberOfCompletedIntervals + 1) * @MontlhyBWInterval, @StartTime)
-- Calculate last day of month
SET @MonthlyBWLDOMNextInterval = DATEADD(DAY, DATEDIFF(DAY, @MonthlyBWLDOMNextInterval, DATEADD(DAY, -1, DATEADD(M, DATEDIFF(MONTH, 0, @MonthlyBWLDOMNextInterval) + 1, 0))), @MonthlyBWLDOMNextInterval)
-- Calculate the last day of the week for the month
SET @MonthlyBWLDOMNextInterval = DATEADD(DAY, -(7 - DATEPART(WEEKDAY, @MonthlyBWLDOMNextInterval) + @MonthlyBWDoW % 7), @MonthlyBWLDOMNextInterval)
END
SET @NextMaintenanceWindow = @MonthlyBWLDOMNextInterval
END ELSE BEGIN
-- Calculate the next interval
DECLARE @MonthlyBWNextInterval DATETIME; SET @MonthlyBWNextInterval = DATEADD(MONTH, @MonthlyBWNumberOfCompletedIntervals * @MontlhyBWInterval, @StartTime)
-- Set the date to the first day of the month
SET @MonthlyBWNextInterval = DATEADD(DAY, -(DAY(@MonthlyBWNextInterval) - 1), @MonthlyBWNextInterval)
-- Set the date to the first day of week in the month
SET @MonthlyBWNextInterval = DATEADD(DAY, (7 - DATEPART(WEEKDAY, @MonthlyBWNextInterval) + @MonthlyBWDoW) % 7, @MonthlyBWNextInterval)
-- Calculate date based on the week number to add
SET @MonthlyBWNextInterval = DATEADD(WEEK, @MonthlyBWWeek-1, @MonthlyBWNextInterval)
IF DATEADD(MINUTE, @Duration, @MonthlyBWNextInterval) < @Now BEGIN
-- Recalc for the next month interval
SET @MonthlyBWNextInterval = DATEADD(MONTH, (@MonthlyBWNumberOfCompletedIntervals + 1) * @MontlhyBWInterval, @StartTime)
-- Set the date to the first day of the month
SET @MonthlyBWNextInterval = DATEADD(DAY, -(DAY(@MonthlyBWNextInterval) - 1), @MonthlyBWNextInterval)
-- Set the date to the first day of week in the month
SET @MonthlyBWNextInterval = DATEADD(DAY, (7 - DATEPART(WEEKDAY, @MonthlyBWNextInterval) + @MonthlyBWDoW % 7), @MonthlyBWNextInterval)
-- Calculate date based on the week number to add
SET @MonthlyBWNextInterval = DATEADD(WEEK, @MonthlyBWWeek-1, @MonthlyBWNextInterval)
END
SET @NextMaintenanceWindow = @MonthlyBWNextInterval
END
END ELSE IF @RecurrenceType = @RecurrenceType_MONTHLYBYDATE BEGIN
DECLARE @MontlhyBDInterval INT; SET @MontlhyBDInterval = (@ScheduleDuration / POWER(2,10)) % POWER(2, 4)
DECLARE @MonthlyBDDoM INT; SET @MonthlyBDDoM = (@ScheduleDuration / POWER(2,14)) % POWER(2, 5)
IF @MonthlyBDDoM = 0 BEGIN
/* This is the last day of month logic */
-- Calculate the total number of completed intervals
DECLARE @MonthlyBDLDOMNumberOfCompletedIntervals INT; SET @MonthlyBDLDOMNumberOfCompletedIntervals = ROUND(CAST(DATEDIFF(MONTH, @StartTime, @Now) AS DECIMAL) / @MontlhyBDInterval, 0, 0)
-- Calculate the next interval
DECLARE @MonthlyBDLDOMNextInterval DATETIME; SET @MonthlyBDLDOMNextInterval = DATEADD(MONTH, @MonthlyBDLDOMNumberOfCompletedIntervals * @MontlhyBDInterval, @StartTime)
-- Calculate last day of month
SET @MonthlyBDLDOMNextInterval = DATEADD(DAY, DATEDIFF(DAY, @MonthlyBDLDOMNextInterval, DATEADD(DAY, -1, DATEADD(M, DATEDIFF(MONTH, 0, @MonthlyBDLDOMNextInterval) + 1, 0))), @MonthlyBDLDOMNextInterval)
-- Recalc the next interval if the next interval plus the expected duration is in the past
IF DATEADD(MINUTE, @Duration, @MonthlyBDLDOMNextInterval) < @Now BEGIN
SET @MonthlyBDLDOMNextInterval = DATEADD(DAY, DATEDIFF(DAY, @MonthlyBDLDOMNextInterval, DATEADD(DAY, -1, DATEADD(M, DATEDIFF(MONTH, 0, DATEADD(MONTH, (@MonthlyBDLDOMNumberOfCompletedIntervals + 1) * @MontlhyBDInterval, @StartTime)) + 1, 0))), @MonthlyBDLDOMNextInterval)
END
SET @NextMaintenanceWindow = @MonthlyBDLDOMNextInterval
END ELSE BEGIN
-- Check to make sure we won't loop forever if more than 31 days some how ends up in the token
IF @MonthlyBDDoM > 31 SET @MonthlyBDDoM = 31
-- Adjust the start time to match the next day of month that matches the interval
DECLARE @MonthlyBDStartTime DATETIME; SET @MonthlyBDStartTime = DATEADD(DAY, (31 - DATEPART(DAY, @StartTime) + @MonthlyBDDoM % 31), @StartTime)
-- This loop is used multiple times to search for the next valid date that falls on the desired day of month
WHILE(DATEPART(DAY, @MonthlyBDStartTime) <> @MonthlyBDDoM) BEGIN
SET @MonthlyBDStartTime = DATEADD(DAY, (31 - DATEPART(DAY, @MonthlyBDStartTime) + @MonthlyBDDoM) % 31, @MonthlyBDStartTime)
END
IF DATEADD(MINUTE, @Duration, @MonthlyBDStartTime) > @Now BEGIN
SET @NextMaintenanceWindow = @MonthlyBDStartTime
END ELSE BEGIN
-- Calculate the total number of completed intervals
DECLARE @MonthlyBDNumberOfCompletedIntervals INT; SET @MonthlyBDNumberOfCompletedIntervals = ROUND(CAST(DATEDIFF(MONTH, @MonthlyBDStartTime, @Now) AS DECIMAL) / @MontlhyBDInterval, 0, 0)
-- Calculate the next interval
DECLARE @MonthlyBDNextInterval DATETIME; SET @MonthlyBDNextInterval = DATEADD(MONTH, @MonthlyBDNumberOfCompletedIntervals * @MontlhyBDInterval, @MonthlyBDStartTime)
WHILE(DATEPART(DAY, @MonthlyBDNextInterval) <> @MonthlyBDDoM) BEGIN
SET @MonthlyBDNextInterval = DATEADD(DAY, (31 - DATEPART(DAY, @MonthlyBDNextInterval) + @MonthlyBDDoM % 31), @MonthlyBDNextInterval)
END
-- Recalc the next interval if the next interval plus the expected duration is in the past
IF DATEADD(MINUTE, @Duration, @MonthlyBDNextInterval) < @Now BEGIN
SET @MonthlyBDNextInterval = DATEADD(MONTH, (@MonthlyBDNumberOfCompletedIntervals + 1) * @MontlhyBDInterval, @MonthlyBDNextInterval)
WHILE(DATEPART(DAY, @MonthlyBDNextInterval) <> @MonthlyBDDoM) BEGIN
SET @MonthlyBDNextInterval = DATEADD(DAY, (31 - DATEPART(DAY, @MonthlyBDNextInterval) + @MonthlyBDDoM % 31), @MonthlyBDNextInterval)
END
END
SET @NextMaintenanceWindow = @MonthlyBDNextInterval
END
END
END
INSERT INTO @NextServiceWindow VALUES (@ScheduleToken, @RecurrenceType, @NextMaintenanceWindow, @Duration, @IsGMTTime)
RETURN
END
Thanks in advance for any suggestions!What an ungodly amount of the code for the task!
I tried
SELECT * FROM SCCM_GetNextServiceWindow('00811A9E08221600', 4)
Which is said mean "Occurs the Third Monday of every 1 month(s)" and it returned 2015-03-17. Which is a Tuesday. But it is the third Tuesday.
Turns out that I have British settings on that instance, DATEFIRST is 1. If do SET DATEFIRST 7, I get 2015-03-23. Which is a Monday, but the wrong one.
The current setting of DATEFIRST can be detected with @@DATEFIRST, and that would make the code even more complex.
My gut reaction would be to start over and do it all in C#, where at least I don't have to bother about SET DATEFIRST.
Or maybe first inspect that the ScheduleToken is correct. Maybe it is, but to me that is just an incomprehensible hex string.
Erland Sommarskog, SQL Server MVP, [email protected] -
All of a sudden yesterday I can no longer click the star twice to tell it where to put the bookmark, and even when I click it once it doesn't save the bookmark anywhere. Also many of my toolbar bookmarks are now suddenly missing. I've tried to restore bookmarks and it says it's unable to perform that function. Help!
You can check for problems with the <b>places.sqlite</b> database file in the Firefox profile folder.
*http://kb.mozillazine.org/Bookmarks_history_and_toolbar_buttons_not_working_-_Firefox
*https://support.mozilla.org/kb/Bookmarks+not+saved#w_fix-the-bookmarks-file
*Places Maintenance: https://addons.mozilla.org/firefox/addon/places-maintenance/
Maybe you are looking for
-
I'm not finding software I purchased in my purchase history. Can anyone help lead me to where to find it. I have the software on my IMac and want to install it on my new laptop. I cannot find it? Help! Thanks, Chad
-
Various error messages when trying to sync my Palm Pre with my OWA
I have read several of the postings and I believe I have tried everything. The odd thing is that it worked prior to me being married. When I brought the phone I just entered my work email address and password and it worked instantly. Then at the end
-
How to enter a meeting as a host
Everytime I enter an Adobe Connect meeting, I enter as a participant, however, I am included in the admin group and I should be joining a meeting as a host. This also happens with a few others in my office. Why is this happening? When we check the se
-
Top row of keyboard wrong after goto snow leopard
Just updated from tiger to snow leopard, now the top row keys (using 2 different keyboards that work ok on other macs correctly) do not work correctly: Speaker up vol key: starts dashboard Speaker down vol key: all windows hide Speaker on/off: shows
-
hello board, My husband surprised me with a new Zen V Plus to listen to audio books. Everything seems to be working ok but all of a sudden there is a new "symbol" in the upper right hand corner of the display window that looks like two circular arrow