为什么要这样用呢,这么麻烦!你可以建一个触发器,这样当你插入一条记录的时候不就能得出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 .................
agree to Leony(老树) : 不过这是先插入后修改值: 在delphi中可以直接使用计算字段来完成!
--用计算列比用触发器简单 --下例显示如何使用表达式 ((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
什么意思?什么是先计算出再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只是表达式,又哪来的计算?但在插入时会自动把值计算出来再插入,并不需要你来计算
如果插入量比较大,可这样 insert into inwarehouse (quantity,unit_price,material_id) values(10,100.00,1) .... 插完后做 update inwarehouse set sumprice=quantity*unit_price
只能在记录好给它才行。 insert into inwarehouse (quantity,unit_price,sumprice,material_id) values(10,100.00,10*100.00,1)
values(10,100.00,10*100.00,1)
我就是不想计算它,看来只有先计算一把,再
insert了,不过还是谢啦
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 .................
:
不过这是先插入后修改值:
在delphi中可以直接使用计算字段来完成!
--下例显示如何使用表达式 ((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
insert into inwarehouse (quantity,unit_price,sumprice,material_id)
values (10,100.00,10*100.00,1)
你这values里的10,100.00怎么来?这里的10*100.00只是表达式,又哪来的计算?但在插入时会自动把值计算出来再插入,并不需要你来计算
如果插入量比较大,可这样
insert into inwarehouse (quantity,unit_price,material_id)
values(10,100.00,1)
....
插完后做
update inwarehouse
set sumprice=quantity*unit_price
insert into inwarehouse (quantity,unit_price,sumprice,material_id)
values(10,100.00,10*100.00,1)
的方法是可行的