我有一个数字类型的字段,想Select出来的结果以科学计数法显示,请问函数怎么写?

解决方案 »

  1.   

    重要  默认情况下,SQL Server 根据截止年份 2049 解释两位数字的年份。即,两位数字的年份 49 被解释为 2049,而两位数字的年份 50 被解释为 1950。许多客户端应用程序(例如那些基于 OLE 自动化对象的客户端应用程序)都使用 2030 作为截止年份。SQL Server 提供一个配置选项("两位数字的截止年份"),借以更改 SQL Server 所使用的截止年份并对日期进行一致性处理。然而最安全的办法是指定四位数字年份。
    当从 smalldatetime 转换为字符数据时,包含秒或毫秒的样式将在这些位置上显示零。当从 datetime 或 smalldatetime 值进行转换时,可以通过使用适当的 char 或 varchar 数据类型长度来截断不需要的日期部分。下表显示了从 float 或 real 转换为字符数据时的 style 值。值 输出 
    0(默认值) 最大为 6 位数。根据需要使用科学记数法。 
    1 始终为 8 位值。始终使用科学记数法。 
    2 始终为 16 位值。始终使用科学记数法。 
    在下表中,左列表示从 money 或 smallmoney 转换为字符数据时的 style 值。值 输出 
    0(默认值) 小数点左侧每三位数字之间不以逗号分隔,小数点右侧取两位数,例如 4235.98。 
    1 小数点左侧每三位数字之间以逗号分隔,小数点右侧取两位数,例如 3,510.92。 
    2 小数点左侧每三位数字之间不以逗号分隔,小数点右侧取四位数,例如 4235.9819。  
      

  2.   

    declare @i float
    set @i=123456789
    print 'test:'+convert(varchar(20),@i)这样就行了!
      

  3.   

    declare @i float
    set @i=123456789
    print 'test:'+convert(varchar(20),@i)
    --test:1.23457e+008
      

  4.   


    declare @tb  table(f1 varchar(50))
    insert into @tb
    select '-0.17035866907990846' union
    select '-0.10411846905437244' union
    select '-8.1290807532302473E-2'
    select 
      cast(cast(cast(f1 as float)*100 as numeric(10,1)) as varchar)+'%' as result
    from @tb--结果
    result
    -------------------------------
    -10.4%
    -17.0%
    -8.1%(3 行受影响)
      

  5.   

    用convert转化为字符串,可以设置格式。如楼上。
      

  6.   


    declare @i float
    set @i=123456789
    print 'test:'+convert(varchar(20),@i)
    --test:1.23457e+008
      

  7.   

    --科学计数法的相互转换
    select result = convert(float ,'901206161310000040271400',0)/*
    result                                                
    ----------------------------------------------------- 
    9.0120616131000006E+23(所影响的行数为 1 行)
    */
    select result = cast(9.0120616131000006E+23 as decimal(24,0))/*
    result                     
    -------------------------- 
    901206161310000060000000(所影响的行数为 1 行)*/
      

  8.   

    declare   @str   decimal(30,8)  
      select   @str='124232342143242342342.234234'  
      select   @str  
      go  
      declare   @str1   float  
      select   @str1='124232342143242342342.234234'  
      select   @str1  
                                                                         
     /*
    ---------------------------------------
    124232342143242342342.23423400(1 行受影响)
    ----------------------
    1.24232342143242E+20(1 行受影响)
    */
      

  9.   


    declare   @str1   float  
      select   @str1='124232342143242342342.234234'  
      select   @str1                                                        
    ----------------------------------------------------- 
    1.2423234214324234E+20(所影响的行数为 1 行)