create table # (产品编号 char, 产品名称 char(10), 进货数量 int  , 单价 int ) insert # select '1', 'aaa', 10, 40 union select '2', 'bbb', 20, 50 
union select '3', 'ccc' ,40, 100
select产品编号,  产品名称, 进货数量, 单价,  总金额 from
(select '产品编号' 产品编号,'产品名称' 产品名称 ,'进货数量' 进货数量,'单价' 单价,'总金额' 总金额,产品编号 as id  
from #
union all 
select 产品编号,产品名称,cast(进货数量 as varchar),cast(单价 as varchar),cast (进货数量*单价 as varchar) 
as 总金额, 产品编号  as id from #) a
order by id ,产品编号 desc

解决方案 »

  1.   

    declare tempcur cursor
    for
    select * from tablename
    order by 产品编号open tempcurfetch next from tempcurWHILE @@FETCH_STATUS = 0
       BEGIN
        fetch next from tempcur
    end  
    close tempcur
      

  2.   

    declare tempcur cursor
    for
    select *,单价*进货数量 总金额 from tablename
    order by 产品编号open tempcurfetch next from tempcurWHILE @@FETCH_STATUS = 0
       BEGIN
        fetch next from tempcur
    end  
    close tempcur