select *,[新列]=(F1+F2*2)/F3 from tablename

解决方案 »

  1.   

    create table 表A(F1 int , F2 int ,F3 int ,f4 =(F1+F2*2)/F3 )
      

  2.   

    declare @str varchar(30),@sql varchar(1000)
    set @str='(F1+F2*2)/F3'
    set @sql='select '+@str+' from 表A'
    exec(@sql)
      

  3.   

    create table tt(A numeric(8,2),B numeric(8,2),C numeric(8,2),S varchar(200))
    insert tt select 1,2,3,'(B+C)*5'
    insert tt select 5,3,6,'C*0.1'
    insert tt select 3,2,5,'B/3'
    go
    create procedure p_dd
    asset nocount on
    declare @s varchar(500)
    declare @a numeric(8,2),@b numeric(8,2),@c numeric(8,2)
    declare  dd_cursor cursor for
    select A,B,C,S from tt
    open  dd_cursor
    fetch next from dd_cursor into @a,@b,@c,@s
    while @@fetch_status=0
     begin
       select @s='update tt set A='+rtrim(ltrim(@s))+'  where current of dd_cursor'  
       exec(@s)
       fetch next from dd_cursor into @a,@b,@c,@s
     end
    close dd_cursor
    deallocate dd_cursor
    set nocount off
    select * from tt  exec p_dd 用游标解决的.
      

  4.   

    hityou1()提供了好的思路,A列在表中不存在,但可以使用 alter table 来添加计算列
     得分。