question

Mikael B avatar image
0 Likes"
Mikael B asked Mikael B commented

ORDER BY ABS() in Storage system query?

Hi, I wonder if its possible to ORDER BY absolute values in a storage system query. The code I have been trying to use is:

return Storage.system.findItem("WHERE SKU IS $1 AND Item.item.ExpiryDate IS $3 ORDER BY ABS($2-Item.slot.storageObject.zone) ASC", 0, token.SKU, Zone, expDate);

SKU is an indexed item label, ExpiryDate is an item label, but not indexed, zone is a label on storage racks.

This code gives these error messages:

Compiler Console:

Invalid sql function ABS

System Console:

exception: FlexScript exception: Invalid query int Storage.System.querySlots() at <no path> c: <no path> i: <no path>

I have also tried replacing ABS() with Math.fabs(), but this just returns different error messages.

Am I doing something wrong, or is there some other workaround to ORDER BY absolute values in a storage system query?

By some googling I know ORDER BY ABS() is supported in normal SQL queries.

The reason for trying to ORDER BY absolute values, is I want to find an item in the closest zone to $2 Zone. The zone label is an integer label with values from 1-18.

FlexSim 20.0.10
queryflexsim 20.0.10finditemorder by
· 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.

Joerg Vogel avatar image Joerg Vogel commented ·
0 Likes 0 ·

1 Answer

Lars Jacobsen avatar image
1 Like"
Lars Jacobsen answered Mikael B commented

You have explicit tell FlexSim to evaluate it as FlexScript by using curly brackets

return Storage.system.findItem("WHERE SKU IS $1 AND Item.item.ExpiryDate IS $3 ORDER BY {Math.fabs($2-Item.slot.storageObject.zone)} ASC", 0, token.SKU, Zone, expDate);

From the User Manual:

FlexScript Expressions: you can use any FlexScript expression within an SQL expression. In some cases, however, you may need to escape the expression using curly braces. This is often required when using the square bracket [ ] in FlexScript, since it has different meaning in SQL than in FlexScript. This causes some errors parsing expressions like WHERE MyCol = Table("MyTable")[1][1]. In this case you can instead escape the FlexScript expression within the SQL using curly braces { }, as follows: WHERE MyCol = { Table("MyTable")[1][1] }.

· 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.

Mikael B avatar image Mikael B commented ·

Thank you!

0 Likes 0 ·