Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server MS SQL SERVER-将int转换为price格式_Sql Server - Fatal编程技术网

Sql server MS SQL SERVER-将int转换为price格式

Sql server MS SQL SERVER-将int转换为price格式,sql-server,Sql Server,我有这样的记录 Price 0 Price 23 Price 555 当我使用选择。。。铸造(价格为十进制(10,2)) 我得到一个奇怪的错误:如果价格是0=我得到.00而不是0.00。所有其他变化的工作(23去23.00,因为我想)。如何修复零?如果您使用的是SQL Server>=2012,则可以使用以下格式: declare @Price int = 0 select format(@Price, 'N') --General format select format(@Price, '

我有这样的记录

Price 0
Price 23
Price 555
当我使用选择。。。铸造(价格为十进制(10,2))


我得到一个奇怪的错误:如果价格是0=我得到.00而不是0.00。所有其他变化的工作(23去23.00,因为我想)。如何修复零?

如果您使用的是SQL Server>=2012,则可以使用以下格式:

declare @Price int = 0
select format(@Price, 'N') --General format
select format(@Price, 'C') --Currency format

您可以在表中使用适当的表列,而不是变量

我确信以前已经问过(并回答过),但一个选项是,您只需在表示层中处理此问题。看起来更像是数据库客户端设置什么类型的价格?@ahmedabdelqader int
declare@Price int set@Price=0选择cast(@Price as decimal(10,2))
Result=
0.00
这里有什么问题?