表中有一列数据是这样的
0.2500
0.5000
1.0000
2.0000
……
要求转成
0.25
0.5
1
2
这种,没有小数位的就取整数,有小数位的,小数后的0全去掉

解决方案 »

  1.   

    select CAST(col as float) from tb 
      

  2.   


    --我自己随意写写的,LZ瞅瞅--> 测试数据: [tb]
    if object_id('[tb]') is not null drop table [tb]
    create table [tb] (col numeric(5,4))
    insert into [tb]
    select 0.2500 union all
    select 0.5000 union all
    select 1.0000 union all
    select 2.0000--开始查询
    select left(col,len(col)+1-patindex('%[^0.]%',reverse(CONVERT(varchar(100),col)))) from tb--结束查询
    drop table [tb]/*
    -----------------------------------------
    0.25
    0.5
    1
    2(4 行受影响)