SQL Server : cast money and 2,3 or 4 decimal places

时间:2019-01-15 18:06:30

标签: sql sql-server

I wrote a query that displays the number and maximum number of decimal places from a given column. It can by two, three or four decimal places.

I would like cast this number as money, but that the number of decimal places would not be cut off to two.

select
    reverse(concat(replicate('0', case when @maxSpaces > 2 then @maxSpaces else 2 end - licznik), val)) value,
    replace(replace(convert(varchar, cast(reverse(concat(replicate('0', @maxSpaces - licznik), val)) as money), 1), ',', ' '), '.', ',') as value_money
from 
    @TABval

enter image description here

I want to get exactly this format:

enter image description here

1 个答案:

答案 0 :(得分:1)

这里有两种变体,可以使用文化参数来获得所需的输出

ans <- dplyr::left_join(A,B, by "ID")