Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 update one field from another

Author  Topic 

Justplainbill
Starting Member

1 Post

Posted - 2002-10-02 : 10:20:12
This is for an inventory table. When the inventory Field is changed or a new record inserted, I would like to set another field to 1.

This is what I have and it throws a lot of errors.I know next to nothing about Transact-SQL and could use some assistance.

CREATE TRIGGER upd_flag on (MyTable)
For UPDATE
AS
if update (Inventory)
Update MyTable SET tbl_Flag = 1
Where Inventory (select inventory FROM inserted)

Any help would be appreciated.
Thanks
Bill




nr
SQLTeam MVY

12543 Posts

Posted - 2002-10-02 : 10:24:53
CREATE TRIGGER upd_flag on (MyTable)
For UPDATE
AS
if update (Inventory)
Update MyTable
SET tbl_Flag = 1
from inserted
Where MyTable.Inventory = insertd.inventory

or you could

if update (Inventory)
Update MyTable SET tbl_Flag = 1
Where Inventory in (select inventory FROM inserted)



==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -