日期:2014-05-19  浏览次数:20581 次

如何把999999999变成999,999,999
数据库表的字段是char型。

存储的数据是999999999。

现在望另外一个表内插入,需要把999999999变成999,999,999

该怎么处理呢?

谢谢!

------解决方案--------------------
declare @s char(20)
set @s= '999999999 '

select cast(cast(@s as int)/1000000 as varchar)+ ', '
+cast(cast(@s as int)/1000000 as varchar)+ ', '
+cast(cast(@s as int)/1000000 as varchar)

--999,999,999
------解决方案--------------------
DECLARE @X varchar(50)
set @X= '999999999 '
SELECT SUBSTRING(REPLACE(@X, '999 ', '999, '),1,LEN(@X)+2)
/*
999,999,999
*/
------解决方案--------------------
declare a char(9)
declare b varchar(11)
set a= '999999999 '
set b=substring(a,1,3)+ ', '+substring(a,4,6)+ ', '+substring(a,7,9)
------解决方案--------------------
select convert (varchar(20),cast(999999999 as money),1)
------解决方案--------------------
select replace(convert(varchar,cast(999999999 as money),1), '.00 ', ' ')