# MSSQL activerecord uses bad syntax

**URL:** <https://www.ruby-forum.com/t/mssql-activerecord-uses-bad-syntax/57161>\
**Category:** Rails\
**Created:** [April 7, 2006, 4:57pm UTC](https://www.ruby-forum.com/t/mssql-activerecord-uses-bad-syntax/57161 "2006-04-07T16:57:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![matthewmurcia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7cd45c/32.png) [@matthewmurcia](https://www.ruby-forum.com/u/matthewmurcia)\
**Post date:** [April 7, 2006, 4:57pm UTC](https://www.ruby-forum.com/t/mssql-activerecord-uses-bad-syntax/57161/1 "2006-04-07T16:57:38Z")

</div>

Hi all,

I’m trying to get rails up on mssql for a friend, does anyone have  
experience? We’re working on a Windows XP box with MSSQL 2000 (no  
service pak), and both rails (1.1) and MSSQL are on the same box. I’m  
running into a bug (I think) where activerecord is using this syntax:

SELECT TOP 1 \* FROM users WHERE (users.user = ‘jbgnuumnbu’)

However, users.user is not a valid syntax in MSSQL. Why doesn’t AR  
handle this? Arn’t other people using this without problems?

Found the error running rake migrate.

–  
Matthew B. :: removed\_email\_address@domain.invalid  
Resume & Portfolio @ [http://madhatted.com](http://madhatted.com)

---

<div class="post-metadata">

**Author:** ![matthewmurcia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7cd45c/32.png) [@matthewmurcia](https://www.ruby-forum.com/u/matthewmurcia)\
**Post date:** [April 7, 2006, 6:39pm UTC](https://www.ruby-forum.com/t/mssql-activerecord-uses-bad-syntax/57161/2 "2006-04-07T18:39:17Z")

</div>

Looks correct to me.  
users is the table, and user is the column. tablename.columnname is  
always  
acceptable because of possible ambiguity.

@user = User.find\_by\_username(‘jbgnuumnbu’) would return exactly what  
you  
see there.

---

<div class="post-metadata">

**Author:** ![matthewmurcia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7cd45c/32.png) [@matthewmurcia](https://www.ruby-forum.com/u/matthewmurcia)\
**Post date:** [April 7, 2006, 10:26pm UTC](https://www.ruby-forum.com/t/mssql-activerecord-uses-bad-syntax/57161/3 "2006-04-07T22:26:12Z")

</div>

Brian H. wrote:

> Looks correct to me.  
> users is the table, and user is the column. tablename.columnname is  
> always  
> acceptable because of possible ambiguity.

Well it may work in find\_by, yeah. The error was from the  
validates\_as\_unique, so I’ve gone and changed it to not use the table  
name. I’m not sure if the rest of rails uses it as well. Another  
frustrating point has arisen though.

The rake tests uses a DBI string for the “host” argument of the mssql db  
dump/import tool (called scrtxfr or something). The host argument  
_actually_ needs to be just the host. If I change the host in  
database.yml, I make rails no longer connect to mssql via AR.

Is anyone out there using mssql?

–  
Matthew B. :: removed\_email\_address@domain.invalid  
Resume & Portfolio @ [http://madhatted.com](http://madhatted.com)
