Select PIN from database?

Hello,
I have a database with a table that has PIN numbers as one of the columns.
I'm trying to have it so when an employee enters a pin number on a keypad they are granted access to a door. I have an OPC tag for access granted, and an OPC tag for the entered PIN number.

Is there a way to compare the value of the entered PIN number to the PIN's in the database then enable the access granted tag to TRUE?

Thank you

There are a few variations on how to accomplish this. Given the constraints (a PIN tag and an access tag) I would simply use a gateway tag change script.

  1. Add a gateway tag change script which triggers on a PIN tag value change.
  2. In that script, query the database for that PIN.
  3. Process the results and write a value back to the access tag.

You could do this on a tag event script also - I just prefer consolidating tag event scripts to a central gateway location.

I would create a third tag, an expression tag (Boolean, Event Driven), that would hold the logic for determining the value of the 'access granted' tag. While this logic could be in a Tag Change script, I like the additional flexibility a separate tag awards.
For example, in addition to verifying that an entered PIN exists in a dataset, the expression could include a timeout period:

(lookup({[.]PIN_Dataset}, {[.]Input_PIN}, -1, 0, 0) > 0)
// lookup(dataset, lookupValue, noMatchValue, [lookupColumn], [resultColumn])
&& (secondsBetween({[.]Input_PIN.Timestamp}, now()) < 10) 
// Less than 10 seconds have passed since PIN tag updated.

In this expression, there's a fourth tag assumed, a dataset tag which caches the query for list of authorized PINs.
You'll still need handle comm-fail to the device (erroneous timestamp update), clearing PIN after auth window, writing to output tag, etc., likely within a Tag Change script (as mentioned by @aspatchek2013).