Skip to main content
September 18, 2008
Answered

Making a query object with only certain columns?

  • September 18, 2008
  • 4 replies
  • 516 views
I need to make several identical charts using different queries, each using the same columns, say "name" and "age". I figured I could use a makeChart(query) function for this. The trick is, I need to ensure each query I pass in contains the variables "name" and "age".

Rather than have the app blow up when I dont have the right column names, I figured I could have makeGraph() only accept a custom query object containing "name" and "age" as columns. Then when I run all my queries, I can copy the results into this query object and pass that to the makeChart() function. Is this possible?
This topic has been closed for replies.
Correct answer -__cfSearching__-
What about passing the column names as a parameter? Then the column names could be dynamic. You could set whatever defaults you want. Name and age if you prefer.

4 replies

September 19, 2008
Thanks for all the feedback! You guys are probably right, I am trying to overcomplicate things. I will go with the passing of the query + list of columns. Dan's QoQ approach seemed like it would achieve what I originally wanted, but I've read performance is not very stellar using this approach.

And I guess I should have been more clear on the 2 column issue - "name" and "age" columns were just examples, in reality I have 7 columns to pass. The list of columns should work well to get all 7. Thanks!!
Inspiring
September 18, 2008
> I could approach it that way, but I have about 7 different columns to pass so
> I'd have to pass in 8 parameters each time (query name + 7 cols).

Well: two. The query, and the list of columns.

I'd approach this by just passing in a query, and stipulating in the hint
for the argument that it must have specific columns. Within the method,
check the correct columns are there, and if not: raise an exception.
Garbage in: garbage out. I think you are overcomplicating things with what
you're suggesting.

Conversely, you could have two arguments:
- a query (required)
- a list of column mappings (optional)

If there's no mappings, then the correct columns must be in place. If
there's the mapping list, use those ones instead. There's - of course -
still no guarantee that the columns in the mapping list will be in the
query, but there's only so much one can do to accommodate the calling code.

--
Adam
September 18, 2008
I could approach it that way, but I have about 7 different columns to pass so I'd have to pass in 8 parameters each time (query name + 7 cols).

It'd be awesome if I could just say copy my query into this custom query object. Then all I'd need to worry about is the columns being in the right order during copy.
Inspiring
September 18, 2008
> I could approach it that way, but I have about 7 different columns to pass so I'd have
> to pass in 8 parameters each time (query name + 7 cols).

Why? If the chart function only uses two of the columns, you would just need to pass in the query object and the two column names that will be used for charting. Though if for some reason you needed all columns, you could always use the query "columnList" variable.

> It'd be awesome if I could just say copy my query into this custom query object.
> Then all I'd need to worry about is the columns being in the right order during copy.

Yes, but you would still have to tell the object what columns to use for the chart. It seems much simpler to just pass the column names into your function and skip the complication of creating a new object.

-__cfSearching__-Correct answer
Inspiring
September 18, 2008
What about passing the column names as a parameter? Then the column names could be dynamic. You could set whatever defaults you want. Name and age if you prefer.