Hi,

Thanks for the suggestion, that didn't work though.  I tried a few variations 
but it doesn't seem to want to use it as a column name unless it's preceded by 
a ':' char.

I was able to use the following, it's not as clean as I would like but seems to 
do the job.

        ds = DB.fetch("SELECT #{field_name} AS CITY, TO_CHAR(COUNT(*)) AS MYVAL 
FROM #{table_name} GROUP BY #{field_name}")
        ds.each{|r| puts r[:myval]}

The COUNT(*) was being returned as scientific notation for some reason so I 
changed it to CHAR in the SELECT.

Cheers,
Kim

On 2011-04-12, at 7:55 AM, Jason Rogers wrote:

> Have you tried this: city =
> DB[table_name].where(field_name.downcase.to_sym => 'NEW YORK')
> 
> On Apr 11, 9:06 pm, kdf <[email protected]> wrote:
>> Hi,
>> 
>> Is it possible to convert a variable to use as a fieldname in a select
>> clause ?
>> 
>> I'm parsing Oracle's data dictionary and would like to select from any
>> table with a field matching a certain field name
>> 
>> i.e. field names can be FROM_CITY, CITY, TO_CITY, etc.
>> 
>> query_tables = DB[:dba_tab_columns].where({:column_name.like('%CITY
>> %')} & {:owner => 'ME'})
>> 
>> for table in query_tables
>>         table_name = table[:table_name]
>>         field_name = table[:column_name]
>>         city = DB[table_name].where(field_name => 'NEW YORK')
>>         puts "#{table_name} - #{city.count}"
>> end
>> 
>> I need to convert field_name to a valid field reference.
>> 
>> Thoughts ?
>> 
>> Kim
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sequel-talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/sequel-talk?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to