I am trying to query a GlobalTable1 using SQL, but the column name is present in token.col in the token, how to access the token.col value in the sql query
I am trying to query a GlobalTable1 using SQL, but the column name is present in token.col in the token, how to access the token.col value in the sql query
Concatenate the label value and the query string.
"SELECT [" + token.col + "] FROM tableName WHERE..."
Yeah it working fine Thanks for the Answer, Now, I just need to Query two column in WHERE which matches the value, can you please help out in this, i am attaching the file with thisFetch_Table_using_Token_and_SQL.fsm
- The label on the token is called "Name", not "Col"
- When comparing a column to a string value, the string needs to be enclosed in single quotation marks within the query (WHERE [Name] == 'A'), so you need to add those to the query string in front of and after the label value.
- You need to convert the number value from "token.Num" to a string before you can insert it into the query like this (string.fromNum(token.Num))
- You only write WHERE once, then write multiple checks separated by AND or OR
Table result = Table.query("SELECT * FROM Test1 \
WHERE [Name] = '"+token.Name+"' AND [Num] = "+string.fromNum(token.Num)+"");
With all that said, values that you want to compare columns to can more easily be passed in via the $-syntax. Inserting the label directly into the string is only needed if it represents a column name or SQL clause.
Table result = Table.query("SELECT * FROM Test1 WHERE [Name] = $1 AND [Num] = $2", token.Name, token.Num);
When the query is run, $1 will be replaced by the first value that is passed in after the query, $2 by the second and so on.
Can you please help me out with the example
14 People are following this question.
FlexSim can help you understand and improve any system or process. Transform your existing data into accurate predictions.
FlexSim is a fully 3D simulation software environment. FlexSim can be used to simulate any process in any industry.
FlexSim®, FlexSim Healthcare™, Problem Solved.®, the FlexSim logo, the FlexSim X-mark, and the FlexSim Healthcare logo with stylized Caduceus mark are trademarks of FlexSim Software Products, Inc. All rights reserved.
Privacy | Do not sell or share my personal information | Cookie preferences | Report noncompliance | Terms of use | Legal | © Autodesk Inc. All rights reserved