代码改变世界

科学计数法格式化到整数

2011-06-13 09:50  屠龙解牛  阅读(372)  评论(0编辑  收藏  举报

int通过odbc到varchar发生的问题.eg:format 1.26e+006 into 1260000 

-------------------------------------------------------------------------------------------

ALTER PROCEDURE [dbo].[use4formatucsale2write4ouhongtao]

AS

 SET NOCOUNT ON;

--truncate table dbo.uchome_temp
--
--
--select * into dbo.uchome_temp
--from
--openquery([uchome],'select houseid,sale from uchome_z_house where sale like ''%e+%'' ') B

declare @houseid int,@sale varchar(50)

declare tempCur cursor for  
 select houseid
   ,sale  
         from dbo.uchome_temp
  

  open tempCur
  fetch tempCur into      
    @houseid
    ,@sale 
   

    While @@Fetch_Status = 0
    begin


     declare @numpart varchar(20)
       ,@index varchar(20)
       ,@len int
       ,@eloc int

     set @sale = ltrim(rtrim(@sale))  
     set @len =  len(@sale)
     set @eloc = charindex('e',@sale)
     
     set @numpart = substring(@sale,1,@eloc-1)
     set @index = substring(@sale,@eloc+1,@len-@eloc)
     
     declare @num float ,@indexnum int
     set @num = cast(@numpart as float)
     set @indexnum = cast(@index as int)
     
     declare @fieldint int
     
     set  @fieldint = cast ((@num*power(10,@indexnum)) as int )  
     
     update dbo.uchome_temp set intsale = @fieldint where houseid = @houseid


    fetch next from tempCur into
       @houseid
       ,@sale 
    

   End
 Close tempCur
 Deallocate tempCur