简体   繁体   中英

SQL Server 2005 Linked Server Query Does Not Return Expected Error

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM