Queries and Bracket Notation

Did you know you can access a query without knowing the column names at the time you code? Each ColdFusion query has a property called columnlist. This, obviously, returns the columns of the query. But how do you access the data? Simple, if q is a query and col is one of the columns, then this will return the value at row N:


Now, one thing to remember. ColdFusion allows you to leave off a row number. This is useful for times when you know the query has one row and you just want to grab data from it. However, with bracket notation, you must always use the row number. Don’t forget that when you loop over a query, there is a built-in value, “currentRow”, that points to, you guessed it, the current row.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com