Created
May 20, 2013 13:53
-
-
Save bennadel/5612364 to your computer and use it in GitHub Desktop.
Using A Dynamic Column Name With ValueList() In ColdFusion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
friends = queryNew( "" ); | |
// Add our name column with initial row values. | |
queryAddColumn( | |
friends, | |
"name", | |
"cf_sql_varchar", | |
[ "Sarah", "Tricia", "Jill" ] | |
); | |
// Create a variable that holds our "dynamic" column reference. | |
targetColumn = "name"; | |
// Use the evaluate() function to invoke the valueList() function | |
// using our dynamic column reference. | |
writeDump( | |
evaluate( "valueList( friends.#targetColumn# )" ) | |
); | |
</cfscript> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
valueList( users.id ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
valueList( users[ "id" ] ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
column = users[ "id" ]; | |
valueList( column ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment