问题描述
正如我发现的(在 SQL Server 书籍中):
As I found (in SQL Server books):
\(反斜杠)(Transact-SQL)
将一个长字符串常量分成两行或更多行以提高可读性.
\ (Backslash) (Transact-SQL)
Breaks a long string constant into two or more lines for readability.
和
SELECT 子句 (Transact-SQL)
... $IDENTITY |$ROWGUID
和$PARTITION (Transact-SQL)
返回分区号,对于任何指定的分区函数,一组分区列值将映射到该分区号.
SELECT Clause (Transact-SQL)
...$IDENTITY | $ROWGUID
And
$PARTITION (Transact-SQL)
Returns the partition number into which a set of partitioning column values would be mapped for any specified partition function.
\
和 $
在 T-SQL 特别是 SQL Server 中的使用.
of usage of \
and $
in T-SQL specially SQL Server.
现在,我有一个这样的查询:
Now, I have a query like this:
SELECT \ a, $ b, \11 c, $12 d;
具有如下有效结果:
a | b | c | d
-----+------+-------+-------
0.00 | 0.00 | 11.00 | 12.00
我觉得这个角色有些地方我找不到.
I think there is something that I can't find it about this characters.
我发现如果 货币符号,SQL Server 将删除定义的符号并将值存储为货币数据类型:
Edit :
I found that if a number comes after currency symbols, SQL Server will remove the defined symbol and store the value as a money data type:
而且我认为,SQL Server 将作为部分中最后一个短语的单个货币符号 - 这些部分在公式的 +
和 -
- 之间转换为 0.00
并且仅在 -$
、($)
、(12 + $)
、($) + 12
, $ * (12 - $)
等等,而不是 $ + 1
, 2 * $ -1
.我还发现 $2
与 $2
相同.
And I think, SQL Server translate a single currency symbol that is the last phrase in a part -these parts are between +
and -
- of formula to 0.00
and only at the end of the part like -$
, ($)
, (12 + $)
, ($) + 12
, $ * (12 - $)
or so on, and not $ + 1
, 2 * $ - 1
. Also I found $ 2
is same as $2
.
\
的所有上述行为都相同,这意味着 SQL Server 认为 \
是货币符号!!!
All above behavior is same for \
that means SQL Server thinks \
is a currency symbol!!!
推荐答案
我想检查数据类型,你会发现每个都返回数据类型 money.
I thought to check the datatype and each as you'll notice each returns the datatype money.
WITH CTE
AS
(
SELECT \ a, $ b, \11 c, $12 d
)
SELECT SQL_VARIANT_PROPERTY(a,'baseType') a,
SQL_VARIANT_PROPERTY(b,'baseType') b,
SQL_VARIANT_PROPERTY(c,'baseType') c,
SQL_VARIANT_PROPERTY(d,'baseType') d
FROM CTE
结果:
a b c d
------------------------------ ------------------------------ ------------------------------ ------------------------------
money money money money
这篇关于'\' 和 '$' 在 T-SQL 中的用法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!