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
 SQL Server Development (2000)
 Update trigger

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-01-23 : 10:12:38
Hassan Rostami writes "Hi,
I have a table called MyTable with three fields in it: ID (Primary Key, Field_1, and Field_2
My record set should look like this
ID	Field_1	Field_2
1 1 1_1
2 1 1_2
3 2 2_1
4 2 2_2


I like to use trigger to update Field_2 as soon as a record is inserted into MyTable. It should get the value of Field_1 plus “_” plus assign number 1 to the first record, 2 to the second, etc. The reason is that I have to use Field_2 to call my record set not ID field

I would appreciate you help. I am very new to SQL and do not know how to set the serial number for Field_
Thanks
Hassan"

andre
Constraint Violating Yak Guru

259 Posts

Posted - 2002-01-23 : 10:20:36
There's an article on it here:
[url]http://www.sqlteam.com/item.asp?ItemID=6494[/url]

Go to Top of Page

Nazim
A custom title

1408 Posts

Posted - 2002-01-23 : 10:26:29
follow the link Andre has provided , you will learn all about writing triggers.

This should do what you are looking for.

update m set m.field2=str(i.field1)+"-"+str(i.id) from mytable m
inner join inserted i
on m.id=i.id




--------------------------------------------------------------
Dont Tell God how big your Problem is , Tell the Problem how Big your God is
Go to Top of Page
   

- Advertisement -