1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| ;with matable (monchiffre, madecimal) as
(
select 12345, 2 union all
select 1234 , 0 union all
select 10000, 2
)
select monchiffre, madecimal,
case
when monchiffre / power(10, madecimal) = monchiffre / power(10.0, madecimal)
then cast(monchiffre / power(10 , madecimal) as varchar(max))
else substring(cast(monchiffre / power(10.0, madecimal) as varchar(max)), 1, len(monchiffre)+1)
end as res
from matable
monchiffre madecimal res
----------- ----------- -------
12345 2 123.45
1234 0 1234
10000 2 100 |
Partager