Contents
Can you pass column name as a parameter?
No. That would just select the parameter value. You would need to use dynamic sql. This is not possible. Either use dynamic SQL (dangerous) or a gigantic case expression (slow). You can pass the column name but you cannot use it in a sql statemnt like
How to pass data.frame column names as strings?
So the short answer is basically: pass data.frame column names as strings and use [ [ to select single columns. Only start delving into eval, substitute, etc. if you really know what you’re doing. Personally I think that passing the column as a string is pretty ugly. I like to do something like:
How to pass column name to function stack?
You can just use the column name directly: There’s no need to use substitute, eval, etc. You can even pass the desired function as a parameter: Alternatively, using
How to pass column name to function in DF?
It simply looks for a column in df literally called col1. This behavior is described in ?Extract under the section “Recursive (list-like) Objects”. The simplest, and most often recommended solution is simply switch from $ to [ [ and pass the function arguments as strings:
How to pass column name as function in powerquery?
This version generates an error: We cannot apply operator “<=” to types List and Number (so while it may be referencing column Y1M as intended, it’s comparing the whole column (as a list) to ‘0’ in the first inequality, rather than one entry at a time. Help!! This was very helpful. This was making me a little nuts.
Can You validate a parameter in dynamic SQL?
Then they can execute just about anything they like. With dynamic SQL, always, always, validate the parameters. Alternatively, you can write a CASE statement… This is a bit more long winded, but a whole lot more secure. No. That would just select the parameter value. You would need to use dynamic sql. This is not possible.