Howdy. I''m trying to work with a legacy SQL Server database where some of the table names have spaces in them. I''ve done set_table_name "tablename with spaces", but I can''t get find(:all) to work. I get the following error (because apparently it''s not putting [ ] around the name as is required for SQL Server for names with spaces. ------------------- c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_ adapters/abstract_adapter.rb:88:in `log'': DBI::DatabaseError: Execute (ActiveRec ord::StatementInvalid) OLE error code:80040E14 in Microsoft OLE DB Provider for SQL Server Incorrect syntax near the keyword ''all''. HRESULT error code:0x80020009 Exception occurred.: SELECT * FROM all wells with apis from c:/ruby/lib /ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/connection_adapters/sq lserver_adapter.rb:467:in `select'' from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_recor d/connection_adapters/sqlserver_adapter.rb:227:in `select_all'' from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_recor d/base.rb:431:in `find_by_sql'' ------------------- I see from the exception method that it hasn''t delimited the table name. There may be more than one way to do this in T-SQL, but what I''m familiar with is putting [ ] around the table name. If I do my own manual find_by_sql and put "select * from [all wells with apis]" it works fine. Thanks for any suggestions.
Michael Teter wrote:> If I do my own manual find_by_sql and put "select * from [all wells > with apis]" it works fine. >Could you just create a view on the table without spaces in the name and select off of that? "SELECT * FROM all_wells_with_apis_view;" -- Alan Garrison Cronosys, LLC <http://www.cronosys.com> Phone: 216-221-4600 ext 308
Ok, without other suggestions that''s what I''ll do (and thanks for that suggestion). But I am curious what one would do if modifying the DB were not an option? Are we reduced to doing all _by_sql() calls? MT On 1/16/06, Alan Garrison <alang@cronosys.com> wrote:> Michael Teter wrote: > > > If I do my own manual find_by_sql and put "select * from [all wells > > with apis]" it works fine. > > > > Could you just create a view on the table without spaces in the name and > select off of that? "SELECT * FROM all_wells_with_apis_view;" > > > -- > Alan Garrison > Cronosys, LLC <http://www.cronosys.com> > Phone: 216-221-4600 ext 308 > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >