question

Ashmita G avatar image
0 Likes"
Ashmita G asked Jeanette F commented

CASE WHEN THEN ELSE END SQL

Hi,

I have been trying to implement "Case when then else end" statement in flexsim but I think I am getting the syntax wrong. Could you please guide?

int entry = Table.query("Select label_name from ListName CASE WHEN label_name =$1THEN label_name END", token.label_name)[1][1];

In the above query, I want to check the list (ListName) for the presence of a particular part which matches with the information being carried by the token's label (label_name).

It may so happen that the list may not have a part which matches with the label of the token. In such a case it needs to return a NULL value. Assuming like in SQL, when else is not mentioned in the query it return a NULL value I have left it from this query as well.

FlexSim 20.1.1
flexscriptflexsim 20.1.1sql queriescase when then else end
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

Mischa Spelt avatar image
1 Like"
Mischa Spelt answered Jeanette F commented

I'm not sure what you expected FlexSim to do here, because that's not the way you use CASE WHEN, even in regular SQL.

But it sounds like what you want to do is really just a regular SELECT:

  1. Table result = Table.query("SELECT 1 FROM ListName WHERE label_name = $1", token.label_name);

and then check if there are any rows in the result set (result.numRows > 0).

· 4
5 |100000

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