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.
| Author |
Topic |
|
javaisok
Starting Member
11 Posts |
Posted - 2003-11-13 : 07:47:24
|
| hi all,is it possible to replace some field value before insert with trigger?as i see inserted could not be updated.10x |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2003-11-13 : 07:59:29
|
| If you're using SQL Server 2000, you can write an INSTEAD OF trigger to change the values being inserted. If not, you can write a regular trigger that updates the table by joining to inserted on the primary key column(s).Can you provide more information on exactly what you need to do (include table structures, DDL, and sample data) |
 |
|
|
javaisok
Starting Member
11 Posts |
Posted - 2003-11-13 : 08:09:51
|
| i am traing to replace an order status when new records is beinginserted into table sys_messages when contains value 1 in DATA1 field.at the end IS_EXECUTED must be stored as 1 (it comes as 0 )CREATE TABLE [dbo].[SYS_MESSAGES] ( [MESSAGE_ID] [int] IDENTITY (1, 1) NOT NULL , [FK_TARGET_STORE_ID] [tinyint] NOT NULL , [FK_SOURCE_STORE_ID] [tinyint] NOT NULL , [DATA1] [int] NOT NULL , [DATA2] [int] NOT NULL , [DATA3] [int] NOT NULL , [DATA4] [int] NOT NULL , [MESSAGE] [tinyint] NOT NULL , [MESSAGE_DATE] [smalldatetime] NOT NULL , [IS_SENDED] [tinyint] NOT NULL , [IS_EXECUTED] [tinyint] NOT NULL , [MESSAGE_FK_ID] [int] NOT NULL ) ON [PRIMARY]CREATE TRIGGER ON_SYS_MESSAGES ON [dbo].[SYS_MESSAGES] FOR INSERTASbegin declare @command tinyint declare @fk_order_id int select @command = ins.message, @fk_order_id = ins.data1 from inserted ins if @command = 1 begin -- replace order status update dbo.orders set order_status = 3 where order_id = @fk_order_id -- -- here i must replace field IS_EXECUTED from 0 to 1 ??? ??? endend |
 |
|
|
|
|
|
|
|