有张表b,
  id       b   
 001     10222
 002      9850
......
b字段的数据类型是Char,这些数据是金额,最右边开始是分、角、元、十元......
怎么才能查出带小数的数据:
    b
 200.72

解决方案 »

  1.   

    cast(金额 as decimal(18,2))
    没看懂.
      

  2.   

    把中文那些替换掉,转换成money,然后sum
      

  3.   

    select * ,b-isnull((select sum(b) from b where where ID>a.ID),0)
    from b a
      

  4.   

    select sum(b)*1.0/100 from b
      

  5.   

    --> 测试数据
     
    declare @tb table ([id] int,[b] nvarchar(20))
    Insert into @tb
     select 001,'10222.22' union all 
     select 002,'9850.33'
      
    Select *,convert(decimal(18,2),[b]) as col from @tb
    /*(2 row(s) affected)
    id          b                    col
    ----------- -------------------- ---------------------------------------
    1           10222.22             10222.22
    2           9850.33              9850.33(2 row(s) affected)*/
      

  6.   

    select id,convert(money,b/100.0 )from #B
      

  7.   

    用round\numeric\decimal\str--取保留小數