# Cycle through Column IDs in popup

**URL:** <https://forum.inductiveautomation.com/t/cycle-through-column-ids-in-popup/29544>\
**Category:** Ignition\
**Tags:** database, python, ignition80, scripting\
**Created:** [October 30, 2019, 10:53pm UTC](https://forum.inductiveautomation.com/t/cycle-through-column-ids-in-popup/29544 "2019-10-30T22:53:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![csanyia](https://avatars.discourse-cdn.com/v4/letter/c/48db29/32.png) [@csanyia](https://forum.inductiveautomation.com/u/csanyia)\
**Post date:** [October 30, 2019, 10:53pm UTC](https://forum.inductiveautomation.com/t/cycle-through-column-ids-in-popup/29544/1 "2019-10-30T22:53:26Z")

</div>

I have a page, with a table and several drop downs for the user to customize the query and table data.

From there, I have a popup to modify the data, the ID is passed to the popup, a WHERE ID = X is put in the a new data set and everything is working as intended.

I’m trying to create a “next” and “previous” button on the popup, to cycle through the custom queried results.

I can pass the entire dataset in a new dataset parameter but I’m having trouble figuring out what will need to be done done to identify the NEXT and PREVIOUS IDs.

Thank you for any suggestions.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [June 1, 2020, 8:37pm UTC](https://forum.inductiveautomation.com/t/cycle-through-column-ids-in-popup/29544/2 "2020-06-01T20:37:37Z")

</div>

I don’t know if you found a solution to this, but for posterity, this is what I have used before. I don’t know if there’s an easier way… Definitely open to suggestions!  
This gets the next tank in a list of tanks, and cycles around to the beginning if at the end.

```auto
--Gets the next tank. If we're at the last tank, then returns the first tank
SELECT TOP 1 MIN(TankNumber) as TankNumber, MIN(TankPrefix) as TankPrefix, MIN(TankFarm) as TankFarm FROM (
	SELECT TankNumber, 'A' as SORT, TankPrefix, TankFarm
	FROM cfgTanks
	WHERE TankNumber > {Tank Navigation.TankNumber} AND TankFarm = '{Tank Navigation.TankFarm}'
	
	UNION ALL
	
	SELECT TankNumber, 'B' AS SORT, TankPrefix, TankFarm
	FROM cfgTanks
	WHERE TankNumber = (SELECT MIN(TankNumber) FROM cfgTanks WHERE TankFarm = '{Tank Navigation.TankFarm}')
) C
GROUP BY SORT
ORDER BY SORT ASC

```

And this is to get the previous tank:

```auto
--Gets the previous tank. If we're at the first tank, then returns the last tank
SELECT TOP 1 MAX(TankNumber) as TankNumber, MAX(TankPrefix) as TankPrefix, MAX(TankFarm) as TankFarm FROM (
	SELECT TankNumber, 'A' as SORT, TankPrefix, TankFarm
	FROM cfgTanks
	WHERE TankNumber < {Tank Navigation.TankNumber} AND TankFarm = '{Tank Navigation.TankFarm}'
	
	UNION ALL
	
	SELECT TankNumber, 'B' AS SORT, TankPrefix, TankFarm
	FROM cfgTanks
	WHERE TankNumber = (SELECT MAX(TankNumber) FROM cfgTanks WHERE TankFarm = '{Tank Navigation.TankFarm}')
) C
GROUP BY SORT
ORDER BY SORT ASC

```
