Compatibility of bit type between SqlServer 2000 and SqlServer 2005
Yesterday I had to debug an issue of a product that we are deploying to a production server. We were developing using SqlServer 2005 (express) and the hosting company uses SqlServer 2000 and as soon as we deploy, we got the following exception on one of the operations:
"Syntax error converting the varchar value 'true' to a column of data type bit"
After some debugging (a couple of hours) and after deploying some special debugging versions, we found the issue. In SqlServer 2005, the following query is perfectly legal:
SELECT UserId, Name FROM Users WHERE IsActive = 'true'
(where IsActive is a bit type)
As it turns out, this is not a valid query in SqlServer 2000, throwing above exception. Because of the single quote, SqlServer 2000, interprets the 'true' as a varchar and cannot cast it as bit, so you need to change it to:
SELECT UserId, Name FROM Users WHERE IsActive = 1
This query is valid in SqlServer 2005 and in SqlServer 2000.
This may be something widely known, but it wasn't to me, so I hope this helps you save some debugging time.