August 12, 2004 at 11:29 am
I have a table in sql with these field id,item,cost,quantity,total and i want that whenever some new record entered it automatically fill the toal field with value=cost*quantity or total=cost*quantity how can I do this somebody suggest me to use triggers but i don't know about triggers please help
Thanks
August 12, 2004 at 1:15 pm
I would use a computed column for that.
create table #sales
([id] int,
item varchar(30),
cost money,
quantity int,
total as cost * quantity)
insert #sales
values (1, 'widget', 1.99, 6)
select * from #sales
-- Steve
August 13, 2004 at 3:09 am
Thanks Steve that's what i am looking for.
August 13, 2004 at 8:34 pm
If the computed column were not the last column in the table and a table insert is performed, then must the insert specify the table column names.
i.e. table cols are :
id, item, cost, computed column, qty.
Then does following insert work?
insert tablename values (1,'widget',1.99,,6)
Thanks
Gary Andrews
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply