問題描述
在這個答案中,有一個技巧可以使用ROW_NUMBER()
ORDER BY
子句中帶有常量"的窗口函數(shù):
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?
我嘗試執(zhí)行一個簡單的查詢:
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 中查看的數(shù)據(jù)類型可能很棘手.一個技巧,如果您懷疑,您知道選擇不兼容的類型 并嘗試轉換:
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模板網(wǎng)!