# Table row number

**URL:** <https://forum.inductiveautomation.com/t/table-row-number/26418>\
**Category:** Ignition\
**Created:** [July 10, 2019, 3:00am UTC](https://forum.inductiveautomation.com/t/table-row-number/26418 "2019-07-10T03:00:41Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [July 10, 2019, 3:00am UTC](https://forum.inductiveautomation.com/t/table-row-number/26418/1 "2019-07-10T03:00:41Z")

</div>

Is there a way to show the row number in a table? So if I bound the data in a table to a SQL query, is there a way to show row number 1 to x as another column?

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [July 10, 2019, 3:16am UTC](https://forum.inductiveautomation.com/t/table-row-number/26418/2 "2019-07-10T03:16:04Z")

</div>

Easiest is probably:

`SELECT 0 AS 'MyRowNumber', ......`

In the configureCell extension function of the table:

```auto
if colName == "MyRowNumber":
	return {"text":rowIndex+1}

```

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [July 10, 2019, 12:49pm UTC](https://forum.inductiveautomation.com/t/table-row-number/26418/3 "2019-07-10T12:49:33Z")

</div>

Awesome, thank you!!

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [July 10, 2019, 4:33pm UTC](https://forum.inductiveautomation.com/t/table-row-number/26418/4 "2019-07-10T16:33:04Z")

</div>

Alternatively most databases have some way to do it, SQL Server has the `ROW_NUMBER()` functionality for instance, and MySQL there are work arounds to get it. Depending on the size of your dataset you may want to put it in your SQL query for speed, but you also probably wouldn’t notice any difference till it’s quite large.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [July 10, 2019, 4:47pm UTC](https://forum.inductiveautomation.com/t/table-row-number/26418/5 "2019-07-10T16:47:31Z")

</div>

I’m using MySQL and have a query/stored procedure that works, but my issue was finding a way to call it. I wasn’t able to use a trigger…

“MySql Error: Can’t update table in stored function/trigger because it is already used by statement which invoked this stored function/trigger”

Any idea on how best to call query or procedure?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [July 10, 2019, 4:50pm UTC](https://forum.inductiveautomation.com/t/table-row-number/26418/6 "2019-07-10T16:50:40Z")

</div>

Sure, you want to use this

[https://docs.inductiveautomation.com/display/DOC79/system.db.execSProcCall](https://docs.inductiveautomation.com/display/DOC79/system.db.execSProcCall)

normally the set up is like so

`call = system.db.createSProcCall( "my stored procedure")`  
`system.db.execSProcCall(call)`

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [July 10, 2019, 5:46pm UTC](https://forum.inductiveautomation.com/t/table-row-number/26418/7 "2019-07-10T17:46:24Z")

</div>

Can use the following for MySQL

```auto
SELECT (@row_number := @row_number + 1) AS 'RowNumber',m.ID, m.Description
FROM mytable m
CROSS JOIN
(SELECT @row_number := 0) AS r

```

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [July 10, 2019, 5:46pm UTC](https://forum.inductiveautomation.com/t/table-row-number/26418/8 "2019-07-10T17:46:45Z")

</div>

What I meant, was how/when to call this? I don’t want to call it all of time. Really only after update/insert/delete. Problem is it might not be updated/inserted/deleted from Ignition, which is why I was hoping to use the trigger in SQL.

I’m probably over-thinking this…

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [September 16, 2020, 5:15pm UTC](https://forum.inductiveautomation.com/t/table-row-number/26418/9 "2020-09-16T17:15:42Z")

</div>

Is there any way to call this after sorting occurs? This method works fine, unless you start sorting, then it’s not useful at all. It’s usually not a huge deal, but in this case each column is editable and I need a way to select multiple rows, so I need a column used for grabbing.

Any options?

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [September 17, 2020, 4:04pm UTC](https://forum.inductiveautomation.com/t/table-row-number/26418/10 "2020-09-17T16:04:14Z")

</div>

Any takers on this one? My goal is to simply show a line number from top to bottom, starting at 1. But, the order needs to remain intact regardless if other columns are sorted.

---

<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, 2020, 4:41pm UTC](https://forum.inductiveautomation.com/t/table-row-number/26418/11 "2020-09-17T16:41:19Z")

</div>

Run your dataset through my `view()` expression function with PseudoSQL as follows:

```auto
view("SELECT *, _r+1 AS row", {Root Container.path.to.property})

```

{ Bind the original source to a custom property, then bind table.data as above. }
