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 美元登录表达式
基础教程推荐
- 带更新的 sqlite CTE 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
