Sql server ce
新手。我的桌子有漂浮值。我想选择浮点数,逗号分隔和小数位。像这样
表名 table1
val
1220333
222
36535
我想要这样的结果
val
12,20,333.00
222.00
36,535.00
像印度卢比一样
使用Sql server ce 3.5
答案 0 :(得分:1)
DECLARE @Table1 TABLE
(val int)
;
INSERT INTO @Table1
(val)
VALUES
(1220333),
(222),
(36535)
;
select convert(varchar(50), CAST(val as money), -1) amount from @Table1
select FORMAT(CAST(val AS MONEY),'N','en-in') amount from @Table1
OR
功能
create function to_indian_currency(@n decimal(25,5))
returns varchar(100) as
BEGIN
declare @a varchar(100) = cast(@n as varchar(100))
declare @dec_part varchar(100) =
(select substring(@a, charindex('.',@a), len(@a)-charindex('.',@a)+1))
declare @int_part varchar(100) = (select left(@a, charindex('.',@a)-1))
declare @f int = cast(@int_part as bigint)%1000
declare @q int = cast(@int_part as bigint)/1000
declare @final varchar(100) = ''
while @q > 0
begin
set @final = cast(@q%100 as varchar) + ',' + @final
set @q = @q/100
end
RETURN @final + cast(@f as varchar) + @dec_part
END
从@ Table1中选择dbo.to_indian_currency(val)