Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does this query return a money value?

Tags:

sql

sql-server

Today I wrote a query that should return an error. Instead, it returns the value 15 with column name why and data type money. Do you have an idea why?

select \15why

Result:

why
15.00
like image 606
VoonArt Avatar asked Mar 08 '18 10:03

VoonArt


People also ask

What does money mean in SQL?

The MONEY data type stores currency amounts. TLike the DECIMAL(p,s) data type, MONEY can store fixed-point numbers up to a maximum of 32 significant digits, where p is the total number of significant digits (the precision) and s is the number of digits to the right of the decimal point (the scale).

How do I change the currency in power query?

Hope this helps! In Desktop, in the model, on the Modeling tab, highlight the column or measure and in the ribbon in the Formatting area, use the $ drop down to change the format.

Why is money represented by the currency data type?

The Currency data type is useful for calculations involving money and for fixed-point calculations in which accuracy is particularly important.


1 Answers

You're specifying a constant:

money constants are represented as string of numbers with an optional decimal point and an optional currency symbol as a prefix

So select €15 results in a money constant, and so does select $15, as well as select ¥15.

There's a peculiarity as pointed out by Jeroen in the comments:

Because the yen sign (¥) is a currency indicator, and in some native Japanese character sets, its code point is the same as the one for backslash in ASCII.

See also MSDN: money and smallmoney (Transact-SQL).

So select \15 appears to be equal to select ¥15.

As for the column name: select 5a results in a column with the alias a and a value of 5. Because "a" is not a numeric suffix, it is treated as select 5 as a, where "as" is optional. Instead select 5e would return 5 in an unnamed column, because "e" is a numeric suffix.

So you've discovered a different way to write select ¥15 as why.

like image 194
CodeCaster Avatar answered Oct 11 '22 17:10

CodeCaster