From: Rajat Garg Date: 2008-03-19T00:40:37+09:00 Subject: Re: Issue with SQL like ------=_Part_18142_20971474.1205854845052 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline This is great. Thanks, Paul On Tue, Mar 18, 2008 at 3:16 AM, Paul Mucur wrote: > > On 18 Mar 2008, at 06:21, Rajat Garg wrote: > > I am writing a query - > > Airport.find(:all, :conditions =>["owner_city_state_zip like '%?%'", > > _tempZip.zip]) > Assuming that you are using Rails, you need to do something like this: > > Airport.find(:all, :conditions => ["owner_city_state_zip LIKE ?", > "%#{_tempZip.zip}%"]) > > > Also, how do we write a query to written say, 2 fields out of table > > instead > > of all the fields. > You need to use the `select` option as detailed in the API: > http://www.railsbrain.com/api/rails-2.0.2/doc/index.html?a=M001686&name=find > > For example, if you only wanted to fetch the `id` and `name` fields of > your airport record: > > Airport.find(:all, :select => 'id, name', :conditions => > ["owner_city_state_zip like ?", "%#{_tempZip.zip}%"]) > > Note that you will still get a full Airport instance but only those > fields in the select will have been loaded. > > -- Paul > > -- Rajat Garg Ph: 206-499-9495 Add: 1314 Spring Street, #412 Seattle, WA 98104 Web: http://www.pilotoutlook.com ----------------------------------------------------------------------------------------------------- Flying is the second greatest thrill known to man. Landing is the first! ------=_Part_18142_20971474.1205854845052--