question

asb.p avatar image
0 Likes"
asb.p asked asb.p commented

How to dynamically pass column name into the SQL Query?

Hello

I am trying to write a query in which I want to query certain column of the table based on Item name. This is the following query which I am trying but it is not working

string myName = item.name;
query("SELECT * FROM $1 WHERE [$3] > 0 AND ([Operator] = $2 OR [Operator] = 'AnyOne')"
,reftable("ML1_TaskListTable"),i,myName);
Task Description PartA PartB PartC
1 sdf 0.25 0 0.25
2 d 1.25 2 0
3 a 0 0 3.06
4 h 3 1.75 0

Thanks in advance,

Praneeth Akondi

FlexSim 17.0.13
sql 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.

1 Answer

·
Jacob Gillespie avatar image
3 Likes"
Jacob Gillespie answered asb.p commented

Just insert the string using the + operator:

string myName = item.name;
query("SELECT " + myName + " FROM $1 WHERE [Operator] = $2 OR [Operator] = 'AnyOne'"
,reftable("ML1_TaskListTable"),i);
· 2
5 |100000

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

Mischa Spelt avatar image Mischa Spelt commented ·

A little safer is

"SELECT [" + myName + "] FROM $1"

in case myName happens to contain a space.

3 Likes 3 ·
asb.p avatar image asb.p commented ·

Thank you...! It is very basic... ! But I couldnt get it at the time of coding...!

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.