There are multiple ways to go about this as it will be highly dependent on the rest of your logic. I do not immediately see any errors when looking at either of your samples.
I am looking forward to reviewing your database. You can send it to me by going to the Control Center-> Help-> Mail to Platform Support.
Ensure to check 'Database file' under 'Other files'. Please reference the following ticket number in the body of the email: 2116810
Comment