例如:
原始表格:
-----------------------------------------------------
编号          A1            A2          A3     
 1        30.8886       25.9878      25.8978
-----------------------------------------------------Select A1, A2, A3 from T
之后的效果是:
-----------------------------------------------------
编号          A1            A2          A3     
 1        30.89       25.99      25.90
-----------------------------------------------------
要在查询语句里面实现!
请各位帮帮忙!谢谢了!

解决方案 »

  1.   

    select round(30.8886, 2), round(25.9878,2), round(25.8978,2) /*
    --------------------------------------- --------------------------------------- ------------------------------
    30.8900                                 25.9900                                 25.9000(1 row(s) affected)
    */
      

  2.   

    什么数据类型?
    select  cast(A1 as numeric(28,2) as A1,
    cast(A2 as numeric(28,2) as A2,
    cast(A3 as numeric(28,2) as A3
    from   T 
      

  3.   

    少括号了select  cast(A1 as numeric(28,2)) as A1,
    cast(A2 as numeric(28,2)) as A2,
    cast(A3 as numeric(28,2)) as A3
    from   T 
      

  4.   

    select cast(round(30.8886, 2) as numeric(18,2)) /*
    ---------------------------------------
    30.89(1 row(s) affected)
    */
      

  5.   

    declare @A table(编号 Int,a1 numeric(18,4),a2 numeric(18,4),a3 numeric(18,4))
    insert into @a select 1,30.8886,25.9878,25.8978select * from @a
    select 编号,cast(round(a1,2)as numeric(18,2)),cast(round(a2,2)as numeric(18,2)),cast(round(a3,2)as numeric(18,2)) from @a
      

  6.   

    declare @a table(编号 Int,a1 numeric(18,4),a2 numeric(18,4),a3 numeric(18,4))
    insert into @a select 1,30.8886,25.9878,25.8978
    select 编号,cast(round(a1,2)as numeric(18,2)) a1,cast(round(a2,2)as numeric(18,2)) a2,cast(round(a3,2)as numeric(18,2)) a3 from @a
    -------------------
    编号 a1 a2 a3
    1 30.89 25.99 25.90
      

  7.   


    select round(A1, 2), .... from T
      

  8.   

    Select   round(A1,2),   round(A2,2),  round( A3,2)   from   T
    这就可以了
      

  9.   


    create table t2 (
    编号 int,
            A1   numeric(12,4),
            A2   numeric(12,4),
    A3   numeric(12,4)
    )insert into t2
    values(1,30.8886,25.9878,25.8978)select * from t2/*
    (所影响的行数为 1 行)编号          A1             A2             A3             
    ----------- -------------- -------------- -------------- 
    1           30.8886        25.9878        25.8978(所影响的行数为 1 行)
    */select 编号,cast(a1 as numeric(12,2)),cast(a2 as numeric(12,2)),cast(a3 as numeric(12,2)) from t2/*
    编号                                                       
    ----------- -------------- -------------- -------------- 
    1           30.89          25.99          25.90(所影响的行数为 1 行)
    */
      

  10.   

    create table trr(编号 int,A1 numeric(8,4),A2 numeric(8,4),A3 numeric(8,4))
    insert into trr select 1,30.8886,25.9878,25.8978select 编号,cast(round(A1,2) as numeric(8,2)),cast(round(A2,2) as numeric(8,2)),cast(round(A3,2) as numeric(8,2)) from trr
      

  11.   

    用round后还应用convert或cast转为2位小数才行,不然会变为.xx00
    应用12,13楼的方法
      

  12.   

    不用round()函数先转换吧. cast(a1 as numeric(12,2))会自动进行四舍五入的.