# Finding which control or scripts writes in a table

**URL:** <https://forum.inductiveautomation.com/t/finding-which-control-or-scripts-writes-in-a-table/10917>\
**Category:** General Discussion\
**Created:** [December 14, 2015, 9:32pm UTC](https://forum.inductiveautomation.com/t/finding-which-control-or-scripts-writes-in-a-table/10917 "2015-12-14T21:32:23Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![jruben84](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@jruben84](https://forum.inductiveautomation.com/u/jruben84)\
**Post date:** [December 14, 2015, 9:32pm UTC](https://forum.inductiveautomation.com/t/finding-which-control-or-scripts-writes-in-a-table/10917/1 "2015-12-14T21:32:23Z")

</div>

Hi Everyone:

I have a question for you guys. I have a table in a SQL DB, and ‘something’ is writing in this table, but I don’t know which control or scripts 😠 . I’ve looking for some ‘INSERT INTO’ statements but I can’t find anything. ![:scratch:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/76d1620bec252bfac07050c889ff5a91dc8a9c25.gif ":scratch:")  
I even wonder if some external process is writing in the table, but I don’t know how to track it.

Any suggestions, comments will be appreciated. ![:thumb_left:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/e26afb081ddde6df016df6ee49159cf56aaca688.gif ":thumb\_left:")

Thank you very much in advance.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [December 14, 2015, 9:43pm UTC](https://forum.inductiveautomation.com/t/finding-which-control-or-scripts-writes-in-a-table/10917/2 "2015-12-14T21:43:10Z")

</div>

Hi! Welcome to the forums!

Did you try the find/replace utility (ctrl-F)?

By default it will only look in open windows, but changing it to ALL windows will look in… well… all windows… 😊

---

<div class="post-metadata">

**Author:** ![jruben84](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@jruben84](https://forum.inductiveautomation.com/u/jruben84)\
**Post date:** [December 15, 2015, 1:06am UTC](https://forum.inductiveautomation.com/t/finding-which-control-or-scripts-writes-in-a-table/10917/3 "2015-12-15T01:06:12Z")

</div>

Jordan:

Thank you very much for the welcome. 😃  
And, yes. I used this utility for search the ‘INSERT INTO’ statements but I can’t find anything. ☹

I appreciate your help.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [December 15, 2015, 1:28am UTC](https://forum.inductiveautomation.com/t/finding-which-control-or-scripts-writes-in-a-table/10917/4 "2015-12-15T01:28:19Z")

</div>

If you have a transaction group that writes to the table, then searching for INSERT INTO probably won’t work. Try looking for the table name.

---

<div class="post-metadata">

**Author:** ![jruben84](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@jruben84](https://forum.inductiveautomation.com/u/jruben84)\
**Post date:** [December 15, 2015, 2:53pm UTC](https://forum.inductiveautomation.com/t/finding-which-control-or-scripts-writes-in-a-table/10917/5 "2015-12-15T14:53:22Z")

</div>

Jordan,

Thank you. I’ve been looking for the TS group, but without success.  
I keep trying.

Regards.

---

<div class="post-metadata">

**Author:** ![JGJohnson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jgjohnson/32/29582_2.png) [@JGJohnson](https://forum.inductiveautomation.com/u/JGJohnson)\
**Post date:** [December 15, 2015, 2:59pm UTC](https://forum.inductiveautomation.com/t/finding-which-control-or-scripts-writes-in-a-table/10917/6 "2015-12-15T14:59:24Z")

</div>

[quote=“jruben84”]Jordan,

Thank you. I’ve been looking for the TS group, but without success.  
I keep trying.

Regards.[/quote]

The fastest way to find it would be to do exactly what Jordan just said and use the find/replace utility but search for the table name instead.

---

<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:** [December 15, 2015, 3:14pm UTC](https://forum.inductiveautomation.com/t/finding-which-control-or-scripts-writes-in-a-table/10917/7 "2015-12-15T15:14:11Z")

</div>

Is there any chance you have a stored procedure you are calling from Ignition that writes to the table? You wouldn’t find either INSERT or the table name in the project if there is an indirect path in the database.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [December 15, 2015, 4:20pm UTC](https://forum.inductiveautomation.com/t/finding-which-control-or-scripts-writes-in-a-table/10917/8 "2015-12-15T16:20:07Z")

</div>

The other thing I was thinking was perhaps a transaction group sitting in a different project.

---

<div class="post-metadata">

**Author:** ![jruben84](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@jruben84](https://forum.inductiveautomation.com/u/jruben84)\
**Post date:** [December 15, 2015, 5:43pm UTC](https://forum.inductiveautomation.com/t/finding-which-control-or-scripts-writes-in-a-table/10917/9 "2015-12-15T17:43:03Z")

</div>

Guys,

Thank you. I also search for the table name, and looking for in different projects.  
I will be some kind of crazy because this table writes null data, and I don’t know why… ![:scratch:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/76d1620bec252bfac07050c889ff5a91dc8a9c25.gif ":scratch:")

---

<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:** [December 15, 2015, 7:42pm UTC](https://forum.inductiveautomation.com/t/finding-which-control-or-scripts-writes-in-a-table/10917/10 "2015-12-15T19:42:25Z")

</div>

Temporarily rename or delete the table and see what part of your system starts throwing errors.

---

<div class="post-metadata">

**Author:** ![jruben84](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@jruben84](https://forum.inductiveautomation.com/u/jruben84)\
**Post date:** [December 16, 2015, 2:50pm UTC](https://forum.inductiveautomation.com/t/finding-which-control-or-scripts-writes-in-a-table/10917/11 "2015-12-16T14:50:36Z")

</div>

Ok!! I will do it. Thank you! ![:thumb_left:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/e26afb081ddde6df016df6ee49159cf56aaca688.gif ":thumb\_left:")

---

<div class="post-metadata">

**Author:** ![jruben84](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@jruben84](https://forum.inductiveautomation.com/u/jruben84)\
**Post date:** [December 18, 2015, 2:43pm UTC](https://forum.inductiveautomation.com/t/finding-which-control-or-scripts-writes-in-a-table/10917/12 "2015-12-18T14:43:23Z")

</div>

Sadly, I can’t find which part of ignition writes in the table. I decided write a SQL function to solve this issue. 😮

Thank you! all of you!!  
 ![:thumb_right:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/2026e28c0c425034352c1b75807edf956adc75f4.gif ":thumb\_right:")

---

<div class="post-metadata">

**Author:** ![jruben84](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@jruben84](https://forum.inductiveautomation.com/u/jruben84)\
**Post date:** [January 8, 2016, 7:08pm UTC](https://forum.inductiveautomation.com/t/finding-which-control-or-scripts-writes-in-a-table/10917/13 "2016-01-08T19:08:03Z")

</div>

I know now 🙂 . It was a ‘trigger’ in SQL Server. Someone programmed it, and runs inside the server.  
I didn’t notice that. Thanks for all guys! 😃

---

<div class="post-metadata">

**Author:** ![jim\_lapratt](https://avatars.discourse-cdn.com/v4/letter/j/cc9497/32.png) [@jim\_lapratt](https://forum.inductiveautomation.com/u/jim_lapratt)\
**Post date:** [January 11, 2016, 12:42pm UTC](https://forum.inductiveautomation.com/t/finding-which-control-or-scripts-writes-in-a-table/10917/14 "2016-01-11T12:42:00Z")

</div>

Could you share the function you wrote?

---

<div class="post-metadata">

**Author:** ![jruben84](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@jruben84](https://forum.inductiveautomation.com/u/jruben84)\
**Post date:** [January 21, 2016, 3:18pm UTC](https://forum.inductiveautomation.com/t/finding-which-control-or-scripts-writes-in-a-table/10917/15 "2016-01-21T15:18:51Z")

</div>

Sure, it’s about 200 lines, but I can share the main parts:

```auto
USE [myDB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[machine_Culls](@fecha_ini DATETIME, @fecha_fin DATETIME)
RETURNS @culls TABLE 
	(Fecha DATETIME, Turno INT, Variables VARCHAR(15), Nombre NVARCHAR(80), Componente NVARCHAR(50), Valor BIGINT)

AS
BEGIN	
	DECLARE @tabla TABLE (Fecha DATETIME, Turno INT, Variables VARCHAR(15), Valor INT)
	INSERT INTO @tabla
		SELECT Fecha, Turno, Variables, MAX(Clase) as Valor 
		FROM ( SELECT 					
					CONVERT(VARCHAR(10),t_stamp,120) as Fecha, turno,
					lot_of_variables_here
				FROM
					some_table_here
			  ) AS Source_table
		UNPIVOT( Clase
				 for Variables in (lot_of_variables_here)
				) AS un_pvt
		GROUP BY Fecha, Turno, variables
	
	INSERT INTO @culls 
	SELECT Fecha, Turno, Variables
	CASE Variables	
		WHEN 'some_string' THEN 'other_string'
		-- a lot of cases here
	END AS Nombre,
	CASE Variables	
		WHEN 'some_string' THEN 'some_class'
	END AS Componente,
	Valor
	
	FROM @tabla
	
RETURN
END

```

But well, exists another function that writes in the table. It was inside a trigger and (not programmed by me). The function that I wrote was a -temporal solution- for my problem until I knew about the trigger.

Thanks!
