Script help, preventing redundant rows, overwriting with prepupdate

Jlanderwerlen
You expressed that you were not sure of the goal and did not see work.

My primary goal for this thread is to pick the application’s optimal way to handle manual entry errors. Secondary goal is learning how suggested methods would work.

not an exhaustive list of options, pros, and cons, but here are the options being discussed:

option 1
Allow operators to curate with submit and delete. (this is the current system)

Pros:
If they make an error then they don’t lose any data until they choose to delete some data.
(unless the error is deleting the wrong data)

cons:
my queries are getting excessively complex to total the shift data due to having multiple rows
(maybe I can perform totaling with the hours from the manual entry table in a better way to mitigate this )

Option 2
if duplicate error on insert then update (unique clustered index), and operators curate with submit and delete (like if they entered data, but production was scrapped for something)

pros:
I will always have 1 row for each machine per shift

cons:
complexity is higher (unique clustered index is another thing for me to teach the team going forward)

Data is automatically deleted on an update (if red machine data is written to blue accidentally, then the data for blue machine is gone for that shift)
(can be reduced with a confirm popup)

Option 3
on submit button press, call delete on any machine and shift matching for the last 8 hours, then insert the row

pros:
not complex (no additional training for the team members)

I will always have 1 row for each machine per shift

cons:
Data can be automatically lost like in cons of option 2

Option 4
let operators curate with submit and delete, then at the end of shift, call a script to eliminate redundant rows per machine per shift, keeping only the last entry for each

pros:
I will always have 1 row for each machine per shift
Not complex, no additional training for team
If they make an error then they don’t lose any data until they choose to delete some data or at the shift end (unless the error is deleting incorrectly)

cons:
script scheduling in 8.1.0 is not optimal
not as robust as insert and update on exception
does not clean up the table in a prevention way on data entry


then additionally some tangents arise
like discussion of the 10 digit input, that is now a dropdown to eliminate some writing transpose errors (eliminates invalid numbers from being entered)

the dropdown is using a table for options to eliminate some reading transpose errors (limits available dropdown answers, eliminates errors entering valid numbers on invalid machines for those numbers)

another tangent was row_number() for this application instead of rank()

I hope that clarifies things, but also I can see how the amount of details can be too tedious.
I appreciate the help.

We are going in circles here. If it were my project i would not allow bad data to be entered and then “fix” it later by deleting all but the last row, which could be the bad data. You can either update a row or allow new rows, just select the last row for your report, no delete. If you are a revisionist, why delete it?

not bad data
There is data that is outdated by new data.
There is data that is accidentally overwritten, making it unretrievable.

well there is some data that would be transposed in a few cases I can’t elimnate.
Some dropdown options can be picked wrong, or hours can be entered wrong. So yah, there is some bad data probably.

Sorry, this is bad data IMO

1 Like

FYI, if you want to callout or reference a user, then do it this way… @zacharyw.larson

I still don’t see any work, no script(s), no queries or table structures etc. I have to agree with what others have said, it looks like you are going about things the wrong way. Instead of taking advice you seem to just want help on making things work the way you think they should.

I don’t think you are reading the full posts I make. This could be my fault. After I read what I write, I think it needs to be given more details because language is so complicated.

I include their posted advice in my posts, and inquire about their pros and cons. I try to explain what I have learned to see if I understand it correctly.

I didn’t post any script because I didn’t write any script because I didn’t determine which option to perform. Though I very much appreciate the scripting that bkarabinchak had posted because I did not even understand it at first. Now I think I get it. I think the error that is thrown for a duplicate when using that index type is known to contain the string they listed.

I think this is the flaw. Your report should not require a 1:1 correspondence between shift and operator. IMNSHO. Fix that first and your current problem goes away.

5 Likes

I agree with Phil here. If in real world scenarios it may happen that shifts are split between several operators, and possibly the same operator is on several “sub-shifts”, then why do you want to only have one row ? Especially if wrong data can be entered manually, deleting/updating things automatically seems like a perfect way to create a mess.
This is not a scripting issue, but a database design issue.

4 Likes

@pturmel
were you saying that I do let the operators do their own shift curating of their input?
Capture it in the table.
Then I would pluck out the relevant data with my queries for reports and such.

I thought this was what you meant. Then when @pascal.fragnoud posted, I was not sure what is being recommended. I may have misunderstood.

I think the table is constructed well.
It has the right datatypes and columns.

Let’s take a step backwards for one second. What is the data that your customer wants to know exactly?

Operators put data about the shift into a table.

Machines automatically put data from the shift into a table.

Then I make a bunch of tables from that data for reports and displaying on pages.

Ok but does the customer care to know Operator one was present for 100 products, Operator 2 was present for 150 products, etc. Or do they just care 4000 products were made during shift one on machine one? What ends up in the report?

The numbers side is all taken care of on the automatic side except for hours.
Everything the operators put in is categorical except the hours.
Dropsdowns and a text field for comments section are used for the inputs.