SELECT $(美元符号) [英] SELECT $ (dollar sign)

查看:295
本文介绍了SELECT $(美元符号)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SQL Server方面拥有丰富的经验, 但是突然我发现了这个奇怪的SELECT命令

I have good experience in SQL Server, But suddenly I discovered this strange SELECT command

SELECT $ 

SELECT $ FROM tableName

始终返回标量值为零(0.00), 或所有值为0.00

All the time it returns zero scalar value (0.00), or a new column with all values of 0.00

那是什么?

推荐答案

当SQL Server遇到您的$符号时,它将自动将其转换为money数据类型.由于美元符号后没有显式值,因此SQL Server假定为​​0.00.来自 MSDN :

When SQL Server comes across your $ sign, it automatically converts it into a money data type. Because you don't have an explicit value after the dollar sign, SQL Server is assuming 0.00. From MSDN:

转换为moneysmallmoney时,将整数视为货币单位.例如,整数值4转换为等值的货币4美元(对于us_english,默认语言).浮点值中小数点右边的数字四舍五入为货币值的四个小数位.要转换为整数数据类型的char或varchar数据类型的表达式必须仅由数字和可选的正负号(+或-)组成.前导空格被忽略.转换为money的char或varchar数据类型的表达式还可以包含可选的小数点和前导美元符号($).

When converting to money or smallmoney, integers are assumed to be monetary units. For example, the integer value of 4 is converted to the money equivalent of 4 dollars (for us_english, the default language). Numbers to the right of the decimal in floating-point values are rounded to four decimal places for money values. Expressions of data types char or varchar that are being converted to an integer data type must consist only of digits and an optional plus or minus sign (+ or -). Leading blanks are ignored. Expressions of data types char or varchar converted to money can also include an optional decimal point and leading dollar sign ($).

这篇关于SELECT $(美元符号)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆