列A int
列B int
列C int 
列D  ?
公式为 D=(A+B)/(C*22),结果最好是像50%这样的格式,如果不行,如果保存像50.00,这样的格式,
谢谢帮助!

解决方案 »

  1.   

    update tb
    set  D==cast(round((A+B)*100.0/(C*22),2) as varchar(10)) + '%'
      

  2.   


    declare @table table (a int ,b int,c int)
    insert into @table
    select 10,30,3 union all
    select 20,15,2 union all
    select 2,13,3
    select * from @table/*
    a           b           c
    ----------- ----------- -----------
    10          30          3
    20          15          2
    2           13          3
    */select *,cast((a+b)*100/(c*22) as nvarchar(12))+'%' as d from @table/*
    a           b           c           d
    ----------- ----------- ----------- -------------
    10          30          3           60%
    20          15          2           79%
    2           13          3           22%
    */
      

  3.   


    借楼上数据declare @table table (a int ,b int,c int,d as cast((a+b)*100/(c*22) as nvarchar(12))+'%')
    insert into @table
    select 10,30,3 union all
    select 20,15,2 union all
    select 2,13,3select * from @table
    /*a           b           c           d             
    ----------- ----------- ----------- ------------- 
    10          30          3           60%
    20          15          2           79%
    2           13          3           22%(所影响的行数为 3 行)
    */
      

  4.   


    在D列的公式输入round((A+B)*100.0/(C*22),2)可以,格是为4.550000000
    但在输入cast(round((A+B)*100.0/(C*22),2) as varchar(10)) + '%'就报错?不知道D列要设置成什么样的字段类形