question

Vinay S avatar image
0 Likes"
Vinay S asked Jeanette F commented

Using Flexscript inside {} in SQL query in Table query

Using Flexscript inside { } in Table query is showing error.

The code:

Table.query("SELECT * FROM [Final plan] WHERE [BF01 Press] = { Table("Final plan")[1][BF01 Press] } ORDER BY SortL").cloneTo(Table("P"+m));


Error message: syntax error, unexpected identifier, expecting ')'


Someone suggest how to use it with example.

I know that we can use $1 instead, but I was trying this. Pls, support.

FlexSim 23.0.1
flexscript sql
· 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.

Jeanette F avatar image Jeanette F ♦♦ commented ·

Hi @Shibananda C2, was Felix Möhlmann's answer helpful? If so, please click the "Accept" button at the bottom of their answer. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.

0 Likes 0 ·

1 Answer

·
Felix Möhlmann avatar image
0 Likes"
Felix Möhlmann answered Jason Lightfoot edited

You have to escape the quotation marks around the table name, so they don't interrupt the query string. Quotation marks are also needed around the column name.

Table.query("SELECT * FROM [Final Plan] WHERE [BF01 Press] = { Table(\"Final Plan\")[1][\"BF01 Press\"] } ORDER BY SortL").cloneTo(Table("P"+m));
· 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.

Vinay S avatar image Vinay S commented ·

Hi Thank you.

Actually I'm trying to use variable inside { }, but I'm getting error.

Code:

for(int m = 1; m<=7; m++){

if(m == 4) m = 5;

Table.query("SELECT * FROM [Final plan] WHERE [BF01 Press] = {\"P\" + m } ORDER BY SortL").cloneTo(Table("P"+m));

}



0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦ Vinay S commented ·

Then the m needs to be outside of the string in order to be concatenated correctly:


"....[BF01 Press]='P"+m+"' ORDER BY...."

Notice you don't need to mark anything as FlexScript here - and you don't need to escape quotation marks as you can use apostrophes to mark the string limits in a SQL statement.

1 Like 1 ·
Felix Möhlmann avatar image Felix Möhlmann Vinay S commented ·

It would be helpful to see (at least an excerpt of) the table you are querying. Do the values in the BF01 Press column actually contain the quotation marks?

In your case you shouldn't need the curled braces at all. Just adding the string together should work.

Table.query("SELECT ... [BF01 Press] = '" + "P" + m + "' ORDER BY SortL")
1 Like 1 ·

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.