开发者

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 开发者_Go百科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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜