We’ve just come up against a bit of a gotcha with Microsoft SQLServer 2005.
We’ve been working on a bespoke system for a customer for the past few months, and have been regularly testing against their test databases that they have been sending over, and they’ve been doing the same. Today the system was set up against their live database for the first time, at which point we got an “Ambiguous column name” error being generated whenever they loaded one of their custom query configurations into our system.
This not surprisingly had us flummoxed for a long while, and it wasn’t until I found this blog post that I nailed down what the problem actually is – SQL Server compatibility modes.
The test database that we have been using was originally created on SQL Server 2000, so when it is attached in SQL Server 2005 the system automatically sets the compatibility mode to 80 – the code for SQL Server 2000. Their live database however has recently been recreated in SQL Server 2005, so when that is attached the compatibility mode defaults to SQL Server 2005, and SQL Server 2005 is a lot more picky about certain bits of SQL syntax. As a result their custom query that works fine on the test system, that reuses a particular column twice and sorts by the same column falls foul of the new syntax rules.
Obviously you can get around the problem by switching the compatibility mode back on the new database, but longer term we’ll need to fix the problem.
It’s not the only change between SQL Server 2000 and SQL Server 2005 either – there is a pretty extensive list of all the changes with a probable impact on this blog post.