当前位置: 代码迷 >> Sql Server >> 请教如何转换某一列的格式
  详细解决方案

请教如何转换某一列的格式

热度:33   发布时间:2016-04-24 10:20:43.0
请问怎么转换某一列的格式?
数据库中有个字段“串号”,类型是nvarchar(100)
从excel导入数据的时候没有注意,这列的格式都是像这样的“8.6243902081e+014”
结果导入数据库后显示的样子还是这样:“8.6243902081e+014”
实际上这里应该是:“862439020810000”

请问我不能重新导入,有什么办法能直接修改吗?像excel设置单元格格式为数字就行了,数据库里能不能写个什么语句让他转换成正常的数字样子吗?求大神,谢谢。
------解决方案--------------------
select Convert(numeric,Convert(float,'8.6243902081e+014'))

------解决方案--------------------

declare @a table(a varchar(100))
insert into @a select '8.6243902081e+014'
select convert(float,LEFT(a,charindex('e',a)-1))* 
       power(10.0,convert(bigint,RIGHT(a,len(a)-charindex('e',a)-1))) from @a

------解决方案--------------------
update tb set col1=Ltrim(Convert(float,'8.6243902081e+014'))

------解决方案--------------------
在导入之前,先把excel那一列设置转换为数值之后在导入
你数据库存放此列的格式不要设置为float
要设置为numeric
  相关解决方案