views:

29

answers:

1

I am querying a linked SQL Server and not getting an error that I do get when querying locally.

Something like this:

SELECT CAST(ColumnName AS INT) FROM TableName

and this:

SELECT CAST(ColumnName AS INT) FROM ServerName.DatabaseName.Schema.TableName

The first query when run locally returns an error 'Arithmetic overflow error converting expression to data type int.' because some values are out of range.

However, the second query running from a different server, simply returns all the 'valid' rows.

I expect that this is working as designed, but I have googled and cannot find anywhere that explains the difference in behaviour when querying locally versus distributed. Can anyone point me in the right direction? I'd also like to know if there is some configuration option that would change this.

Thanks in advance.

A: 

Look at the SET ARITHABORT and SET ANSI_WARNINGS options. When both are off, then the overflow error will be suppressed and a NULL will be returned instead. They can be set in (at least) three different places: the connection, the database or the code. That means you can sometimes get unexpected behaviour because someone set a database option and forgot about it, or someone is using a connection library that sets certain options differently by default. More information here:

http://msdn.microsoft.com/en-us/library/ms191203(v=SQL.90).aspx

Pondlife
Both these settings are ON in both of the situations. The behaviour I'm getting is not that a NULL is returned, it is that no row is returned. That is, the table contains 15,000 rows but when I query via the linked server route I only get 3000 rows.
Darren