sql-server - SQL Server : What locale should be used to format numeric values into SQL Server format?

标签 sql-server sql-server-2000 globalization

SQL Server does not accept numbers formatted 似乎使用任何特定的区域设置。 它还不支持具有 0-9 以外数字的区域设置。

例如,如果当前区域设置是孟加拉语,则数字 123456789 将显示为 “১২৩৪৫৬৭৮৯”。这只是数字,不管数字分组是什么。

但是,不变区域设置中的数字也会出现同样的问题,该区域设置将数字格式设置为“123,456,789”,而 SQL Server 不会接受这种格式。

是否存在与 SQL Server 接受的数值相匹配的区域性?或者我是否必须创建一些自定义的“sql server”区域性,从较低级别的格式化例程中自己生成该区域性的规则?

如果我在 .NET 中(但我不是),我可以仔细阅读 Standard Numeric Format strings 。 .NET 中可用的格式代码:

  • c(货币):123.46 美元
  • d(十进制):1234
  • e(指数):1.052033E+003
  • f(定点):1234.57
  • 克(一般):123.456
  • n(数字):1,234.57
  • p(百分比):100.00 %
  • r(往返):123456789.12345678
  • x(十六进制):FF

只有 6 个接受所有数字类型:

  • c(货币):123.46 美元
  • d(十进制):1234
  • e(指数):1.052033E+003
  • f(定点):1234.57
  • 克(一般):123.456
  • n(数字):1,234.57
  • p(百分比):100.00 %
  • r(往返):123456789.12345678
  • x(十六进制):FF

其中只有 2 个生成字符串表示形式,无论如何,在 en-US 语言环境中,SQL Server 都会接受它:

  • c(货币):123.46 美元
  • d(十进制):1234
  • e(指数):1.052033E+003
  • f(定点):1234.57
  • 克(一般):123.456
  • <罢工>n(数字):1,234.57
  • p(百分比):100.00 %
  • r(往返):123456789.12345678
  • x(十六进制):FF

在剩下的两个中,固定取决于区域设置的数字,而不是所使用的数字,留下通用 g 格式:

  • c(货币):123.46 美元
  • d(十进制):1234
  • e(指数):1.052033E+003
  • f(定点):1234.57
  • 克(一般):123.456
  • <罢工>n(数字):1,234.57
  • p(百分比):100.00 %
  • r(往返):123456789.12345678
  • x(十六进制):FF

我什至不能肯定地说 g 格式不会添加数字分组(例如 1,234)。

是否存在按照 SQL Server 期望的方式格式化数字的区域设置?有.NET格式的代码吗? java格式的代码?有Delphi格式的代码吗?有VB格式的代码吗? stdio 格式代码?

拉丁数字

最佳答案

constants 的 SQL Server 规范正在描述 T-SQL 表达式和批处理中可接受的格式:

integer constants are represented by a string of numbers that are not enclosed in quotation marks and do not contain decimal points. Integer constants must be whole numbers; they cannot contain decimals.

decimal constants are represented by a string of numbers that are not enclosed in quotation marks and contain a decimal point.

float and real constants are represented by using scientific notation.

money constants are represented as string of numbers with an optional decimal point and an optional currency symbol as a prefix. Money constants are not enclosed in quotation marks. SQL Server does not enforce any kind of grouping rules such as inserting a comma (,) every three digits in strings that represent money. Commas are ignored anywhere in the specified money literal.

To indicate whether a number is positive or negative, apply the + or - unary operators to a numeric constant. This creates a numeric expression that represents the signed numeric value. Numeric constants use positive when the + or - unary operators are not applied.

好消息是客户端应用程序不需要担心这些要求。客户端应用程序应将数值作为 @parameters 传递,而不是作为 T-SQL 文字常量传递。

关于sql-server - SQL Server : What locale should be used to format numeric values into SQL Server format?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2502491/

相关文章:

sql-server - 我可以在 BIDS 2008 中开发 SSIS 2005 吗?我们可以在 VS 2010 中选择目标框架的方式

sql-server - 如何查找大于的字母数字字符串

asp.net - 如何将 ASP.Net 表单例份验证 loginUrl 全局化为多种语言?

c# - 全局化 C# : Percentage data formatting:

javascript - 如何检查 jQuery Globalize 是否已初始化?

sql - 打开 "September$"的行集失败。检查对象是否存在于数据库中

sql - 在 SSIS 中将月份名称更改为月份编号

sql - SQL 中的数学运算?

SQL Alter 触发器挂起

SQL Server : How to use Cursor to delete records