question

Julio R avatar image
0 Likes"
Julio R asked Julio R commented

How to convert a table to an array

Hello,

I am doing an SQL query and the result is a table with just one column, I want the results in an array and i am using a simple code as such:


Table Busqueda = Table.query("SELECT IEDBDATA.ROW_NUMBER FROM IEDBDATA WHERE [Assembly] = $1","ASDF");

Array arrayFinal;

for(int i=1;i<=Busqueda.numRows;i++){

arrayFinal.push(Busqueda[i][1]);

}

Is there a more direct or simple method than a for loop to transform the Table into an Array?


FlexSim 22.1.2
sqlarraytable
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Jason Lightfoot avatar image
0 Likes"
Jason Lightfoot answered Julio R commented

You want the ARRAY_AGG function:


Table result=Table.query("SELECT ARRAY_AGG([Col 1]) FROM GlobalTable1");
return result[1][1];   //returns the values in 'Col 1' as an array
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Julio R avatar image Julio R commented ·
Thanks @Jason Lightfoot , thats exactly what I wanted
0 Likes 0 ·