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)
 create trigger autonumber

Author  Topic 

dba_raf
Starting Member

2 Posts

Posted - 2008-10-13 : 12:01:10
Hi,
I've this table TAB1:

COD_ID............NAME........DESCRIP

I'd like to create a trigger that when I insert a new record into table TAB1 I get the value of column COD_ID = NAME_0000000001......NAME_0000000002.............NAME_0000000003............NAME_0000000010................(NAME + 10byte autonumber)

for example:

INSERT INTO TAB1 (NAME, DESCRIP)
VALUES ('AAA', 'THIS IS EXAMPLE');

select *
from tab1;

COD_ID....................NAME............DESCRIP
AAA_0000000001.........AAA...........THIS IS EXAMPLE


INSERT INTO TAB1 (NAME, DESCRIP)
VALUES ('BBB', 'THIS IS EXAMPLE2');


select *
from tab1;

COD_ID....................NAME............DESCRIP
AAA_0000000001.........AAA...........THIS IS EXAMPLE
BBB_0000000002.........BBB...........THIS IS EXAMPLE2



INSERT INTO TAB1 (NAME, DESCRIP)
VALUES ('XXX', 'THIS IS EXAMPLE3');


select *
from tab1;

COD_ID....................NAME............DESCRIP
AAA_0000000001........AAA...........THIS IS EXAMPLE
BBB_0000000002.........BBB...........THIS IS EXAMPLE2
XXX_0000000003........XXX...........THIS IS EXAMPLE3


INSERT INTO TAB1 (NAME, DESCRIP)
VALUES ('CCC', 'THIS IS EXAMPLE4');


select *
from tab1;

COD_ID....................NAME............DESCRIP
AAA_0000000001........AAA...........THIS IS EXAMPLE
BBB_0000000002.........BBB...........THIS IS EXAMPLE2
XXX_0000000003........XXX...........THIS IS EXAMPLE3
CCC_0000000004........CCC...........THIS IS EXAMPLE4
.....................................................
.....................................................
.....................................................
.....................................................

How can I write this trigger to get my output??

Thanks in advance!

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2008-10-13 : 12:25:32
Duplicate post: http://www.dbforums.com/showthread.php?t=1634685

If it is not practically useful, then it is practically useless.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-13 : 12:40:42
you just need an identity column in your table and then a calculated column based on it for this
Go to Top of Page
   

- Advertisement -