Logic Machine Forum
SQL COUNT - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: SQL COUNT (/showthread.php?tid=2225)



SQL COUNT - Trond Hoyem - 06.09.2019

Hi

I am having some trouble getting a number from the SQL COUNT.

I am using this conde:
Code:
ant = db:getrow('SELECT COUNT() FROM objects WHERE name LIKE "%status%"')

log(ant)

The result I get from this in the log is then;
* table:
[COUNT()]
  * number: 569


What I need is to just get the number stored in the variable, not the entire table. Any good tips for me?


RE: SQL COUNT - admin - 06.09.2019

Use getone() instead of getrow()


RE: SQL COUNT - Trond Hoyem - 06.09.2019

(06.09.2019, 08:32)admin Wrote: Use getone() instead of getrow()

As a charm!
Perfect.


RE: SQL COUNT - Trond Hoyem - 16.09.2019

(06.09.2019, 08:32)admin Wrote: Use getone() instead of getrow()

Hi

I am now having a similar challenge, but this time with the table I get from the string.split function. I have the following code;
Code:
startHG = string.split(start, '/')
This takes the Group address and splits it to the three values from the addres, giving med the table;

* table:
[1]
  * string: 26
[2]
  * string: 0
[3]
  * string: 0

How can I now get the different values entered in seperate variables? I would like to have a variable for maing group (e.g. mg) that should have the value 26 and so on.


(16.09.2019, 12:47)Trond Hoyem Wrote:
(06.09.2019, 08:32)admin Wrote: Use getone() instead of getrow()

Hi

I am now having a similar challenge, but this time with the table I get from the string.split function. I have the following code;
Code:
startHG = string.split(start, '/')
This takes the Group address and splits it to the three values from the addres, giving med the table;

* table:
[1]
  * string: 26
[2]
  * string: 0
[3]
  * string: 0

How can I now get the different values entered in seperate variables? I would like to have a variable for maing group (e.g. mg) that should have the value 26 and so on.

Nevermind. I found it out by trial and error. The code needs to be;
Code:
startHG = tonumber(string.split(start, '/')[1])

That will get the main group as a number.