一个SQL语句可不行,估计得用游标遍历表中的各条记录,结合动态SQL执行吧。

解决方案 »

  1.   

    不太明白楼主的用意
    用触发器不能实现吗?
    非得用sql数据库解决公式计算的问题吗?
      

  2.   

    create table Tb_UinonConfig(
    @prim1 real
    @arithmetic varvhar(50)
    )
    return @r float
    exec( 'select @r=@prim1'+replace(replace(@arithmetic,'×','*'),'÷','/'))
    go仅适用于四则混合运算
    其他运算还没测试
      

  3.   

    create table Tb_UinonConfig(prim1 real,arithmetic varchar(50))
    insert into Tb_UinonConfig select 100,'+20.5×15÷13.1'
    insert into Tb_UinonConfig select 80 ,'÷2.5×100+23.0'
    insert into Tb_UinonConfig select -80,'+100+(23.0×6)'
    gocreate table #T(prim1 real,arithmetic varchar(50),value real)declare @prim1 real,@arithmetic varchar(50),@s nvarchar(4000)
    declare t_cursor cursor for select * from Tb_UinonConfigopen t_cursorfetch next from t_cursor into @prim1,@arithmeticwhile @@fetch_status=0
    begin
        set @s=N'insert into #T select @prim1,@arithmetic,@prim1'+replace(replace(@arithmetic,'×','*'),'÷','/')
        exec sp_executesql @s,N'@prim1 real,@arithmetic varchar(50)',@prim1,@arithmetic
        fetch next from t_cursor into @prim1,@arithmetic
    end
    close t_cursor
    deallocate t_cursorselect * from #T/*
    prim1   arithmetic        value
    ------- ----------------- ----------- 
    100.0   +20.5×15÷13.1   123.47328
    80.0    ÷2.5×100+23.0   3223.0
    -80.0   +100+(23.0×6)    158.0
    */drop table #T,Tb_UinonConfig