How to use column name as a variable.<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />I want to select some rows from a column ( I have a column named as 'RESOLUTION' in the current data table)
This two lines will work:
======================================
dt = Current Data Table();
dt< 0.);
======================================
If I define 'RESOLUTION' as another variable, it doesn't work:
============================================
dt = Current Data Table();
colA="RESOLUTION";
dt< 0.);
============================================
This will not select any row.
Could someone kindly tell me how could I do this?
Thanks.
Re: How to use column name as a variable.It might make AsColumn() faster if you combine it with Column().
Re: Should you Loop through a data table or use Recode, or use Get Rows Where to change values in a data table
Re: How to use column name as a variable.One thing to watch with using As Column() is that it seems to be much slower than using the eval( parse(..)) syntax for a large data table.
In my case I had a data table with 390k rows and 17 columns.
Using Eval ( Parse ( .... )) took 67 msec to select the rows I was looking for while using the As Column() syntax took 3,600 msec ! ( using HPTime() to measure )
So while the As Column() syntax is a whole lot more readable in the code, if speed matters, it may not be the best option
Re: How to use column name as a variable.Alternatively use the AsColumn function:
colA="RESOLUTION";
dt< 0.)
Re: How to use column name as a variable.It works!!
Many thanks!
Re: How to use column name as a variable.qt,
This will do the trick.
dt = Current Data Table();
colA = "Resolution";
col_expr = "dt << Select Where(:name(\!"" || colA || "\!") > 0.)";
eval(parse(col_expr));
Basically you're creating some dynamic code, and then executing it.