在这个答案中,有一个技巧可以使用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 美元登录表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
将每个子标记转换为具有多个分隔符的单列-SQLConverting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(将每个子标记转换为具有多个分隔符的单列-SQ
如何从多个表创建视图?How can I create a view from more than one table?(如何从多个表创建视图?)
根据前一行内的计算值创建计算值Create calculated value based on calculated value inside previous row(根据前一行内的计算值创建计算值)
如何将表格的前两列堆叠成一列,但也仅将第三How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何将表格的前两列堆
递归 t-sql 查询Recursive t-sql query(递归 t-sql 查询)
将月份名称转换为日期/月份编号(问题和答案的组Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(将月份名称转换为日期/月份编号(问题和答案的组合