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

Here is a puzzle about an error while converting money to decimal.

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

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

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.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.


Discover more from SQL Authority with Pinal Dave

Subscribe to get the latest posts sent to your email.

SQL Error Messages, SQL Scripts
Previous Post
SQL SERVER – Challenge – Puzzle – Usage of FAST Hint
Next Post
SQL SERVER – Challenge – Puzzle – Why does RIGHT JOIN Exists

Related Posts

28 Comments. Leave new

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.