SQL SERVER – Puzzle – Challenge – Error While Converting Money to Decimal

Posted by pinaldave on SQL Authority See other posts from SQL Authority or by pinaldave
Published on Sat, 27 Nov 2010 01:30:35 +0000 Indexed on 2010/12/06 16:57 UTC
Read the original article Hit count: 939

Earlier I wrote SQL SERVER – Challenge – Puzzle – Usage of FAST Hint and I did receive some good comments. Here is another question to tease your mind. Run following script and you will see that it will thrown an error.
DECLARE @mymoney MONEY;
SET @mymoney = 12345.67;
SELECT CAST(@mymoney AS DECIMAL(5,2)) MoneyInt;
GO

The datatype of money is also visually look similar to the decimal, why it would throw following error:

Msg 8115, Level 16, State 8, Line 3
Arithmetic overflow error converting money to data type numeric.

Please leave a comment with explanation and I will post a your answer on this blog with due credit.

Reference: Pinal Dave (http://blog.sqlauthority.com)


Filed under: Pinal Dave, SQL, SQL Authority, SQL Error Messages, SQL Puzzle, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, SQLServer, T SQL, Technology

© SQL Authority or respective owner

Related posts about Pinal Dave

Related posts about sql