# Select PIN from database?

**URL:** <https://forum.inductiveautomation.com/t/select-pin-from-database/100181>\
**Category:** Ignition\
**Created:** [December 23, 2024, 9:53pm UTC](https://forum.inductiveautomation.com/t/select-pin-from-database/100181 "2024-12-23T21:53:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JVeldt](https://avatars.discourse-cdn.com/v4/letter/j/f0a364/32.png) [@JVeldt](https://forum.inductiveautomation.com/u/JVeldt)\
**Post date:** [December 23, 2024, 9:53pm UTC](https://forum.inductiveautomation.com/t/select-pin-from-database/100181/1 "2024-12-23T21:53:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![aspatchek2013](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/aspatchek2013/32/85339_2.png) [@aspatchek2013](https://forum.inductiveautomation.com/u/aspatchek2013)\
**Post date:** [December 23, 2024, 10:00pm UTC](https://forum.inductiveautomation.com/t/select-pin-from-database/100181/2 "2024-12-23T22:00:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Chris\_Bingham](https://avatars.discourse-cdn.com/v4/letter/c/e5b9ba/32.png) [@Chris\_Bingham](https://forum.inductiveautomation.com/u/Chris_Bingham)\
**Post date:** [December 24, 2024, 12:57am UTC](https://forum.inductiveautomation.com/t/select-pin-from-database/100181/3 "2024-12-24T00:57:42Z")

</div>

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:

```python
(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).
