# SQLTags Alarm Edit Goodie

**URL:** <https://forum.inductiveautomation.com/t/sqltags-alarm-edit-goodie/1030>\
**Category:** Archived Topics\
**Created:** [March 7, 2009, 1:46pm UTC](https://forum.inductiveautomation.com/t/sqltags-alarm-edit-goodie/1030 "2009-03-07T13:46:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alai](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@alai](https://forum.inductiveautomation.com/u/alai)\
**Post date:** [March 7, 2009, 1:46pm UTC](https://forum.inductiveautomation.com/t/sqltags-alarm-edit-goodie/1030/1 "2009-03-07T13:46:38Z")

</div>

I have about 30 or more tags set up through this goodie.  
[inductiveautomation.com/prod … ies/?id=17](http://www.inductiveautomation.com/products/factorypmi/goodies/?id=17)

Now I have 3 tags :

Auto\_Cycle\_Started  
Auto\_Cycle\_Completed  
Auto\_Cycle\_Aborted

And another tag:

Batch\_Record

Is there a way to write the Batch\_Record next to all the alarms and events tags in the AlarmLog table, only when I see all the alarms and events that occur between Auto\_Cycle\_Started and Auto\_Cycle\_Completed or between Auto\_Cycle\_Started and Auto\_Cycle\_Aborted, and all other times don’t record a Batch\_Record next to the alarms.

Any insight will be greatly appreciated. This would make it easier to relate the data for the recipe to the alarms and events that occur during the recipe.

E.g. AlarmLog table with the Batch\_Record column added

Auto\_Cycle\_Start Batch\_Record  
Event1 Batch\_Record  
Event5 Batch\_Record  
Alarm7 Batch\_Record  
Auto\_Cycle\_Completed Batch\_Record

---

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [March 7, 2009, 7:57pm UTC](https://forum.inductiveautomation.com/t/sqltags-alarm-edit-goodie/1030/2 "2009-03-07T19:57:41Z")

</div>

As far as I know, you are not able to add fields to the AlarmLog table.

I think you will have to distinguish between alarms, which you want to know about immediately, and data which should be logged for later analysis. It seems to me that what you are trying to do is create a batch record detailing the important events in the course of making a product, ending up with a record like this:

Batch\_Record, Auto\_Cycle\_Started, Auto\_Cycle\_Completed, Auto\_Cycle\_Aborted

This would normally be done using FactorySQL logging, rather than FactoryPMI alarming. You could also log events against the Batch\_Record, although in that case you would end up with a table with multiple entries, like:

Batch\_Record, Event1  
Batch\_Record, Event2  
Batch\_Record, Event3

Let me know if this sounds like what you’re trying to achieve (or if it isn’t!) and I’ll try to help you set things up.

Al

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [March 9, 2009, 4:56pm UTC](https://forum.inductiveautomation.com/t/sqltags-alarm-edit-goodie/1030/3 "2009-03-09T16:56:06Z")

</div>

You can also have FactorySQL log a history of your batches, and then correlate alarms (and anything else) to their batch via the timestamp.

---

<div class="post-metadata">

**Author:** ![chris\_d\_sanders](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/chris_d_sanders/32/3359_2.png) [@chris\_d\_sanders](https://forum.inductiveautomation.com/u/chris_d_sanders)\
**Post date:** [June 23, 2009, 2:01am UTC](https://forum.inductiveautomation.com/t/sqltags-alarm-edit-goodie/1030/4 "2009-06-23T02:01:13Z")

</div>

I have something similar I want to do. While in the ALARM HISTORY window of the client, I would like to be able to see what campaign and batch # I was running when the alarm occurred.

I obviously have an “alarmlog” table fed from sqltags (for 5 individual machines). 2 Master batch lines have 750 alarms each, 2 Final mix lines have 450 alarms each and 1 OIL PLC has about 100 Alarms. (approx.)

So in total approx. 2500 alarms. For 2400 of them, I need recipe name and batch #. For each line (L11-L14) I have 1 table for batch # and start time, and 1 table for recipe name and start time. I need to SOME HOW do a JOIN??? perhaps? and show the recipe and batch # in the same table as the alarms.

So, for example i’ll give you 4 alarm entries and some columns:  
alarmlog table:

AlarmLog\_ndx, active\_time, clear\_time, item\_name, state\_name

1, 2009-06-01 12:00:30, 2009-06-01 12:01:00, L11\_Alarm\_01, Alarm1  
2, 2009-06-01 12:00:35, 2009-06-01 12:05:00, L12\_Alarm\_02, Alarm2  
3, 2009-06-01 12:00:32, 2009-06-01 12:01:12, L13\_Alarm\_03, Alarm3  
4, 2009-06-01 12:00:38, 2009-06-01 12:00:55, L14\_Alarm\_04, Alarm4

(each lines recipe and batch tables are structured the same way)  
L11\_batch table:

ID, batch\_number, start\_time

1, 17, 2009-06-01 12:00:00  
2, 18, 2009-06-01 12:01:30

L12\_recipe table:

ID, recipe\_name, start\_time

1, blackrubber, 2009-06-01 11:45:00  
2, bluerubber, 2009-06-01 12:30:30

So, how do I take a LIST of alarms and get each one to show which recipe and batch was running?

… As a side note, it would be COOL to have the STATE\_NAME dynamic. Just as when you add a tag and can use OTHER tags to drive the severity, it would be cool to INSERT information into the state\_name when the alarm is stored in alarmlog.
