T-SQL 美元登录表达式

T-SQL Dollar Sign In Expressions(T-SQL 美元登录表达式)
本文介绍了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 美元登录表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Number of working days between two dates(两个日期之间的工作日数)
How do I use dateadd to get the first day of last year?(如何使用 dateadd 获取去年的第一天?)
SQL- Count occurrences of a specific word within all stored procedures(SQL- 计算所有存储过程中特定单词的出现次数)
SQL query to make a column of numbers a string(使一列数字成为字符串的 SQL 查询)
T-SQL: Best way to replace NULL with most recent non-null value?(T-SQL:用最新的非空值替换 NULL 的最佳方法?)
Count days in date range with set of exclusions which may overlap(使用一组可能重叠的排除项计算日期范围内的天数)