SQL Server Management Studio STR() 函数居中列数据
SQL Server Management Studio STR() function centers column data
我认为这更像是一个表面问题,是由 SQL Server Management Studio 引起的,但是有人知道为什么当我将 float
转换为 [=12 时我的列数据发生偏移吗=] 使用 STR()
函数?这是 SQL Server Management Studio 中的一个表面错误还是影响我的数据的实际有意义的错误?
有问题的列是第 3 列,如您所见,有多个 1 似乎相对于较大的 10 位数字居中。
用 space 填充。
当 VALUE = 1(浮点数)时,我得到:
len(str(VALUE)) = 10
ascii(str(VALUE)) = 32
ascii(right(str(VALUE),9)) = 32
etc...
char(32) = space
根据msdn:
A short float_expression is right-justified in the specified length, and a long float_expression is truncated to the specified number of decimal places. For example, STR(12,10) yields the result of 12. This is right-justified in the result set.
似乎 "right-justification" 在此上下文中意味着用 spaces 恰好填充一个短值,以便 'number-as-string' 组件位于字符串的远端。如果这不是您想要的,那么您可能需要一个不同的功能。
我认为这更像是一个表面问题,是由 SQL Server Management Studio 引起的,但是有人知道为什么当我将 float
转换为 [=12 时我的列数据发生偏移吗=] 使用 STR()
函数?这是 SQL Server Management Studio 中的一个表面错误还是影响我的数据的实际有意义的错误?
有问题的列是第 3 列,如您所见,有多个 1 似乎相对于较大的 10 位数字居中。
用 space 填充。
当 VALUE = 1(浮点数)时,我得到:
len(str(VALUE)) = 10
ascii(str(VALUE)) = 32
ascii(right(str(VALUE),9)) = 32
etc...
char(32) = space
根据msdn:
A short float_expression is right-justified in the specified length, and a long float_expression is truncated to the specified number of decimal places. For example, STR(12,10) yields the result of 12. This is right-justified in the result set.
似乎 "right-justification" 在此上下文中意味着用 spaces 恰好填充一个短值,以便 'number-as-string' 组件位于字符串的远端。如果这不是您想要的,那么您可能需要一个不同的功能。