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
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).
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.
The Currency data type is useful for calculations involving money and for fixed-point calculations in which accuracy is particularly important.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With