select    所占比例=
cast(
cast(
10*100./100   as   decimal(10,2)
)   as   varchar
)+'%'   试下吧:
select    所占比例=
cast(
cast(
COLUMN1*100./COLUMN_LAST as   decimal(10,2)
)   as   varchar
)+'%'   

解决方案 »

  1.   

    没这个函数,只有自己写了create function dbo.fnPercent (@numerator float, @denominator float)
    RETURNS VARCHAR(10)
    AS
    BEGIN
    DECLARE @R DECIMAL(10,2)
    SET @R=@numerator/@denominator*100
    RETURN CAST(@R AS VARCHAR)+N'%'
    ENDselect dbo.fnPercent(2,3) AS percentagepercentage
    ----------
    66.67%
      

  2.   

    if object_id('tempdb..#')is not null drop table #
    go
    create table #(col1 int,col2 int)
    insert # select 1,3
    insert # select 2,6
    insert # select 4,7
    select ltrim(cast(col1*100.0/col2 as decimal(16,2)))+'%' from #
    /*------------------------------------------
    33.33%
    33.33%
    57.14%
    */
      

  3.   

    ---测试数据---
    if object_id('[tb]') is not null drop table [tb]
    go
    create table [tb]([col1] int,[col2] int,[col3] int,[col4] int,[col5] int,[col6] int,[col7] int,[col8] int,[col9] int,[col10] int,[col11] int,[col12] int,[col13] int)
    insert [tb]
    select 244,0,2,0,0,0,0,3,0,0,0,0,759 union all
    select 154,0,3,0,0,3,0,0,0,0,0,0,477 union all
    select 112,0,1,0,0,0,0,3,0,0,0,0,268 union all
    select 281,0,0,0,0,0,0,5,0,0,0,0,636 union all
    select 13,0,0,0,0,0,0,0,0,0,0,0,23 union all
    select 50,0,0,0,0,0,0,0,0,0,0,0,97
     
    ---查询---
    select *,
      newcol=cast(cast(col1*100.0/col13 as dec(18,2)) as varchar)+'%'
    from tb---结果---
    col1        col2        col3        col4        col5        col6        col7        col8        col9        col10       col11       col12       col13       newcol                          
    ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- ------------------------------- 
    244         0           2           0           0           0           0           3           0           0           0           0           759         32.15%
    154         0           3           0           0           3           0           0           0           0           0           0           477         32.29%
    112         0           1           0           0           0           0           3           0           0           0           0           268         41.79%
    281         0           0           0           0           0           0           5           0           0           0           0           636         44.18%
    13          0           0           0           0           0           0           0           0           0           0           0           23          56.52%
    50          0           0           0           0           0           0           0           0           0           0           0           97          51.55%(所影响的行数为 6 行)