Formatting an SQL numeric query result with an arbitrary number of decimal places

后端 未结 6 367
孤街浪徒
孤街浪徒 2021-01-15 04:51

I have a database table with these two columns:

  • Amount: numeric (18,0)
  • DecimalPlaces: numeric (18,0)

This table can store amounts in va

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-15 05:40

    In SQL server you can :

    select stuff(convert(varchar,amount) ,
             len(convert(varchar,amount)) - DecimalPlaces - 1, 0, ".")
    

提交回复
热议问题