Hugo Kornelis (5/4/2010)
Good observation, Christian. The format of the error message, which looks quite different from errors that are thrown by SQL Server, is also an indication that there is a different source of the error.
This just gets more and more interesting. I have been able to reproduce the SSMS-only behaviour when connecting to a default instance of SQL Server 2005 from SSMS and SQLCMD. I found this in Books Online:
SQL Server Management Studio uses the Microsoft .NET Framework SqlClient for execution in regular and SQLCMD mode in Query Editor. When sqlcmd is run from the command line, sqlcmd uses the OLE DB provider. Because different default options may apply, you might see different behavior when you execute the same query in SQL Server Management Studio in SQLCMD Mode and in the sqlcmd utility.
So, I thought...that explains that. Except that it doesn't. I get a proper SQL-Server-generated error for all the tests presented so far when connected to a named instance of SQL Server 2008 - connecting from SSMS or SQLCMD! The error is:
.Net SqlClient Data Provider: Msg 8115, Level 16, State 2, Line 1
Arithmetic overflow error converting expression to data type numeric.
The error is captured in a Profiler trace under the Errors and Warnings: User Error Message category, so this is definitely a SQL Server error. This does not happen when connected to SQL Server 2005 - the error definitely comes from the provider not SQL Server.
Here's a repro to try (notice no value is returned to the client - it is written to a temporary table):
SELECT ROUND(0.5, 0) AS a INTO #a;
SELECT message = ERROR_MESSAGE(),
number = ERROR_NUMBER(),
line = ERROR_LINE(),
severity = ERROR_SEVERITY(),
state = ERROR_STATE();
DROP TABLE #a;
That produces full error details when connected to 2008, but runs without error on 2005 - even from SSMS. Finally, to add to the evidence, this is a screenshot of the results of SELECT ROUND(0.5, 0) when run from SQLCMD against 2005 and 2008:
Answers on a postcard, please!