你可以这样:insert into inwarehouse (quantity,unit_price,sumprice=quantity*unit_price,material_id)values(10,100.00,10*100.00,1)

解决方案 »

  1.   

    insert into inwarehouse (quantity,unit_price,sumprice,material_id)
       values(10,100.00,10*100.00,1)
      

  2.   

    也就是先计算出再insert啦,
    我就是不想计算它,看来只有先计算一把,再
    insert了,不过还是谢啦
      

  3.   

    为什么要这样用呢,这么麻烦!你可以建一个触发器,这样当你插入一条记录的时候不就能得出sumprice的值来了!create trigger sumprice
    as
      declare a int
      declare b int
      declare c int  
      select a=quantity,b=unit_price from inserted
      set c=a*b
      update inwarehouse set sumprice = c where .................
      

  4.   

    agree to  Leony(老树) 
    :
    不过这是先插入后修改值:
    在delphi中可以直接使用计算字段来完成!
      

  5.   

    --用计算列比用触发器简单
    --下例显示如何使用表达式 ((low + high)/2) 计算 myavg 计算列。CREATE TABLE mytable 
       (
        low float,
        high float,
        myavg AS (low + high)/2
       )insert mytable (low,high) values(1,2)insert mytable (low,high) values(4,5)select * from mytable
      

  6.   

    什么意思?什么是先计算出再insert?
    insert into inwarehouse (quantity,unit_price,sumprice,material_id) 
         values (10,100.00,10*100.00,1)
    你这values里的10,100.00怎么来?这里的10*100.00只是表达式,又哪来的计算?但在插入时会自动把值计算出来再插入,并不需要你来计算
      

  7.   


    如果插入量比较大,可这样
    insert into inwarehouse (quantity,unit_price,material_id)
       values(10,100.00,1)
    ....
    插完后做
    update inwarehouse
    set sumprice=quantity*unit_price
      

  8.   

    只能在记录好给它才行。
    insert into inwarehouse (quantity,unit_price,sumprice,material_id)
       values(10,100.00,10*100.00,1)
      

  9.   

    你可以在SQL Server中加计算字段,名字设为你想要得名字,就可以实现自动计算的效果。
      

  10.   

    我觉得foolishchao(亚超)
    的方法是可行的