# Error in IF and SQL query

**URL:** <https://forum.inductiveautomation.com/t/error-in-if-and-sql-query/38467>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [September 8, 2020, 11:59am UTC](https://forum.inductiveautomation.com/t/error-in-if-and-sql-query/38467 "2020-09-08T11:59:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![etlikmilos](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@etlikmilos](https://forum.inductiveautomation.com/u/etlikmilos)\
**Post date:** [September 8, 2020, 11:59am UTC](https://forum.inductiveautomation.com/t/error-in-if-and-sql-query/38467/1 "2020-09-08T11:59:18Z")

</div>

Hi, I try to learn the script in Ignition and I have this code and I need to compare the values ​​from the query SQl “duplicity”. this way the code returns an error to me.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/5/254a3d09c5cda71b36171f3ab117d579be42dc4c.png)

```auto
parms = {
	"carovyKod" : self.getSibling("NumericEntryField_9").props.value
	}
	id = system.db.runNamedQuery("Technic","technics/Revize/duplicita",parms);
	#id = system.dataset.toPyDataSet(id);
	self.getSibling("Label_11").props.text = id;
	#id.getValueAt(0,0);        
	if id is None:
		self.getSibling("Label_11").props.text = "test";
		rz = {
			"ch1": self.getSibling("check_el_box").props.selected,
			"ch2": self.getSibling("check_ruc_nar").props.selected,
			"ch3": self.getSibling("check_prod_privod").props.selected,
			"ch4": self.getSibling("check_od_privod").props.selected,
			"nazevSpotrebice": self.getSibling("TextField").props.text,
			"inventarniCislo": self.getSibling("NumericEntryField").props.value,
			"vyrobce": self.getSibling("TextField_1").props.text,
			"rokVyroby": self.getSibling("NumericEntryField_0").props.value,
			"vyrobniCislo": self.getSibling("TextField_2").props.text,
			"majitel": self.getSibling("TextField_3").props.text,
			"skpinaPouyivani": self.getSibling("Dropdown").props.value,
			"typOznac": self.getSibling("TextField_4").props.text,
			"Un": self.getSibling("NumericEntryField_1").props.value,
			"In" : self.getSibling("NumericEntryField_2").props.value,
			"Pn" : self.getSibling("NumericEntryField_3").props.value,
			"TridaOchrany" : self.getSibling("Dropdown_0").props.value,
			"datumKontroly" : self.getSibling("DateTimeInput").props.value,
			"TypKontroly" : self.getSibling("Dropdown_1").props.value,
			"poznamka" : self.getSibling("TextField_5").props.text,
			"vyhodnoceni" : self.getSibling("Dropdown_2").props.value,
			"sestava" : self.getSibling("Dropdown_3").props.value,
			"delkaPrivodu" : self.getSibling("NumericEntryField_4").props.value,
			"OdporVodice" : self.getSibling("NumericEntryField_5").props.value,
			"IzolkacniOdpor" : self.getSibling("NumericEntryField_6").props.value,
			"metoda" : self.getSibling("Dropdown_4").props.value,
			"I" : self.getSibling("NumericEntryField_7").props.value,
			"bezMaleNapeti" : self.getSibling("NumericEntryField_8").props.value,
			"zkouskaChodu" : self.getSibling("Dropdown_5").props.value,
			"celkoveHodnoceni" : self.getSibling("Dropdown_6").props.value,
			"terminDalsikontroly" : self.getSibling("DateTimeInput_0").props.value,
			"provedl" : self.getSibling("TextField_6").props.text,
			"cisloProtokolu" : self.getSibling("NumericEntryField_9").props.value,
			"OznaceniTypu" : self.getSibling("TextField_4").props.text
		}
		system.db.runNamedQuery("Technic","technics/Revize/revizeAdd",rz);   
	else:	
		if id.getValueAt(0,0) > 1:
			system.perspective.openPopup("info",'RZ/popup/info')
		

```

So can you help me please?

---

<div class="post-metadata">

**Author:** ![etlikmilos](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@etlikmilos](https://forum.inductiveautomation.com/u/etlikmilos)\
**Post date:** [September 8, 2020, 12:00pm UTC](https://forum.inductiveautomation.com/t/error-in-if-and-sql-query/38467/2 "2020-09-08T12:00:44Z")

</div>

And here is my SQL code for duplicity 🙂

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/f/dff7242be3e0e894b73491a0cfbdce644811f2b2.png)

---

<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:** [September 8, 2020, 12:11pm UTC](https://forum.inductiveautomation.com/t/error-in-if-and-sql-query/38467/3 "2020-09-08T12:11:04Z")

</div>

The error says the length of your dataset is zero. ‘id’ should always return a dataset, and never a None object. So, it goes the else portion of the script and errors because row 0 doesn’t exist.

Instead, try `if id.rowCount == 0:`

---

<div class="post-metadata">

**Author:** ![etlikmilos](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@etlikmilos](https://forum.inductiveautomation.com/u/etlikmilos)\
**Post date:** [September 8, 2020, 12:36pm UTC](https://forum.inductiveautomation.com/t/error-in-if-and-sql-query/38467/4 "2020-09-08T12:36:45Z")

</div>

Perfect thank you very much 😃
