# Save alarm log to SQL Server table

**URL:** <https://forum.inductiveautomation.com/t/save-alarm-log-to-sql-server-table/28313>\
**Category:** Ignition\
**Created:** [September 17, 2019, 12:42pm UTC](https://forum.inductiveautomation.com/t/save-alarm-log-to-sql-server-table/28313 "2019-09-17T12:42:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![David.Bell](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@David.Bell](https://forum.inductiveautomation.com/u/David.Bell)\
**Post date:** [September 17, 2019, 12:42pm UTC](https://forum.inductiveautomation.com/t/save-alarm-log-to-sql-server-table/28313/1 "2019-09-17T12:42:29Z")

</div>

Hello, I am looking to create my own alarm logging and am hoping that Ignition has a simple method for doing this. I have several boolean PLC tags that I want to track and when they are active ,insert a record with timestamp into SQL Server and then when cleared, write the timestamp to the corresponding record in the SQL table. Other than writing scripts, is there a more simple method to handle this?

Thanks.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 17, 2019, 3:05pm UTC](https://forum.inductiveautomation.com/t/save-alarm-log-to-sql-server-table/28313/2 "2019-09-17T15:05:25Z")

</div>

> [@David.Bell](#):
>
> Other than writing scripts

Not really. You could use a transaction group with any change on the boolean as a the trigger, but you'll get separate entries in the DB for each change, and sometimes some extras. A decent database can tie the edges together for you (lead() or lag() functions) but it isn't trivial.

A transaction group for each boolean doesn't scale, though. The closest you could get would be a gateway tag change event that subscribes to all interesting booleans and does the above, but includes a reference to the source boolean in what it stores in the DB.

---

<div class="post-metadata">

**Author:** ![David.Bell](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@David.Bell](https://forum.inductiveautomation.com/u/David.Bell)\
**Post date:** [September 17, 2019, 5:16pm UTC](https://forum.inductiveautomation.com/t/save-alarm-log-to-sql-server-table/28313/3 "2019-09-17T17:16:21Z")

</div>

Thank you. Too bad there is not a canned way to do this. This is a typical process.

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [September 17, 2019, 7:38pm UTC](https://forum.inductiveautomation.com/t/save-alarm-log-to-sql-server-table/28313/4 "2019-09-17T19:38:00Z")

</div>

The built in Alarm Journal does this automatically.  
It writes every transition for each configured alarm to the alarm tables with timestamps.  
Any particular reason you can’t use the alarm journal?

---

<div class="post-metadata">

**Author:** ![David.Bell](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@David.Bell](https://forum.inductiveautomation.com/u/David.Bell)\
**Post date:** [September 17, 2019, 9:46pm UTC](https://forum.inductiveautomation.com/t/save-alarm-log-to-sql-server-table/28313/5 "2019-09-17T21:46:51Z")

</div>

I would like to use it, but I do not want to have 2 records per incident. For example, I would like to insert a record and then update it when the alarm is acknowledged/cleared. Is that possible?

Thanks.

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [September 18, 2019, 11:57am UTC](https://forum.inductiveautomation.com/t/save-alarm-log-to-sql-server-table/28313/6 "2019-09-18T11:57:01Z")

</div>

Not that I am aware of.  
But you can do some record combining to pull alarm data.  
something like

```auto

   SELECT source 
  ,max(CASE WHEN eventtype = 0 THEN eventtime END) AS activetime
  ,max(CASE WHEN eventtype = 2 THEN eventtime END) AS ackedtime
  ,max(CASE WHEN eventtype = 1 THEN eventtime END) AS clearedtime
   FROM alarm_events
   GROUP BY source

```
