question

Thomas JR avatar image
0 Likes"
Thomas JR asked anthony.johnson commented

SQL NOT operator does not work

Hi folks,

the following SQL-query doesn't work for me (ignore the odd variable names):

Table dummy = Table.query("SELECT SUM(Average*Count) FROM Input_data WHERE Variable = $1 AND Hello_world NOT IN ('Iphone', 'I like cats')", parameter_1);

However, when I remove the NOT operator, the query works fine. I believe the syntax is correct according to FlexSim documentation, so what's going on??

And FYI, I do not use any special characters for my original variable names, only what you'll find in the english alphabet.

FlexSim 20.1.3
flexsim 20.1.3sql queries
5 |100000

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

Benjamin W2 avatar image
1 Like"
Benjamin W2 answered anthony.johnson commented

Flexsim only supports a subset of SQL commands, and unfortunately, NOT is not one of them. You can see a list of what is supported here:

https://docs.flexsim.com/en/20.1/Reference/DeveloperAdvancedUser/SQLQueries/

Is there a way that you could create an array that your value is IN? You could then pass that array to the query.


· 3
5 |100000

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

anthony.johnson avatar image anthony.johnson ♦♦ commented ·

FYI the NOT operator will be supported in the next feature release, 20.2.

1 Like 1 ·
Thomas JR avatar image Thomas JR commented ·

@Benjamin W2 oh well, I actually had a quick look at the documentation but I simply assumed that such an essential operator would be supported, despite not being listed. Luckily in my case it is feasible to instead negate the list of values within the IN clause. However there may be other future cases where it is easier to use the NOT operator. I wonder why the developers chose to leave it out.

0 Likes 0 ·
Benjamin W2 avatar image Benjamin W2 Thomas JR commented ·

@Thomas JR, I agree that a NOT would be a great addition. Feel free to post an idea. Our dev team looks at that frequently, and the more people who ask for it, the more likely it will be implemented.

1 Like 1 ·
martin.j avatar image
2 Likes"
martin.j answered Thomas JR commented

Hi @Thomas JR, I have been frustrated by the missing NOT clause as well, but managed to make a query similar to yours with a little workaround:

Table dummy = Table.query("SELECT SUM(Average*Count) FROM Input_data WHERE Variable = $1 AND 1 <> (Hello_world IN ('Iphone', 'I like cats'))", parameter_1);

The IN keyword will return a true or false if the result is in the specified list/array, so if you specify that you want the result only where it is not true, it is practically the same as having a NOT statement. I admit that it is a bit clunky to read but it works.

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

Thomas JR avatar image Thomas JR commented ·

@martin.jensen Nice solution! I'm gonna apply it in my model.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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