Jump to content
  • 0

Triggered Action - While Do and Variables Adding Extra Records


kpcollier

Question

Hello. I have a trigger that is taking the difference of two dates (Date_Start and Date_End) and creating a new record for each one. 

In Example, if Date_Start is 5/10/2021 and Date_End is 5/12/2021, three new records should be inserted into the table, one for 5/10, 5/11, and 5/12. 

My problem is that my trigger is creating extra records in the table. Taking a look at the table and the trigger below may help understand the problem I am having. 

 

Here is the trigger. Var daycount is getting the difference in days. This number should be the amount of records that will be created. The 'Date' field in the DO section receives a different date for each one in the range and is what is being used for my Calendar Datapage.

 

 

However, as you can see below, the 'daycount' or something didn't get the correct number of days, because there are more records in the table then there should be. You can see the first record has the Date Start and Date End fields that the trigger should run off of. You can also see the 3 records that should be there - the ones with a value in Date. However, there are also 4 records that do not have a Date, Date_Start, or Date_End. I am not sure where those records are coming form. 

 

 

I am suspecting something is going wrong with the daycount variable or with adding 'i' to daycount. But, it all looks correct to me, so I am not sure. Another thought was maybe the SELECT statements in the daycount variable are selecting the wrong dates?

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

I tried this, and it is definitely because you are using #inserted as Destination and source. Maybe create a table variable and store the initial #inserted table there so you won't select from a table that's being constantly modified through the loop, or create another table altogether, that's where it conflicts.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...