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
这里有什么问题?