T-SQL Dollar Sign In Expressions(T-SQL 美元登录表达式)
问题描述
在这个答案中,有一个技巧可以使用ROW_NUMBER()ORDER BY 子句中带有常量"的窗口函数:
In this answer, there is a trick which allows to use the ROW_NUMBER() windowed function with a 'constant' in the ORDER BY clause:
SELECT ROW_NUMBER() OVER (ORDER BY $/0)
FROM master..spt_values
在谷歌搜索后,我找不到美元符号在这种情况下的含义是什么?
After some search in Google, I can't find what dollar sign means in this context?
我尝试执行一个简单的查询:
I've tried to execute a simple query:
SELECT $;
它返回0.
有人能解释一下吗?
推荐答案
这只是一个 money 常量(T-SQL 称之为字面量).
It's just a money constant (what T-SQL calls literals).
如果您看到表达式 $2.50,您可能不会感到惊讶,它只是另一个常量.
You presumably would have been less surprised if you saw the expression $2.50, which would just be another constant.
其他一些示例:select £,¢,¤,¥,€ 也都返回 0.
Some other examples: select £,¢,¤,¥,€ all return 0s also.
确定您在 T-SQL 中查看的数据类型可能很棘手.一个技巧,如果您怀疑,您知道选择不兼容的类型 并尝试转换:
It can be tricky to determine what type of data you're looking at in T-SQL. One trick, if you suspect you know what type it is is to pick an incompatible type and attempt the conversion:
select CONVERT(date,$)
结果:
Msg 529, Level 16, State 2, Line 1
Explicit conversion from data type money to date is not allowed.
这篇关于T-SQL 美元登录表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:T-SQL 美元登录表达式
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- SQL 临时表问题 2022-01-01
