Advertisement

10.13.2008 at 08:43AM PDT, ID: 23809817 | Points: 250
[x]
Attachment Details

Create Trigger autonumber

Asked by chirpl_chirpl in MS SQL Server, SQL Server 2005

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 underscore 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!Start Free Trial
[+][-]10.13.2008 at 08:55AM PDT, ID: 22703472

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.13.2008 at 08:58AM PDT, ID: 22703497

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.13.2008 at 09:29AM PDT, ID: 22703772

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.13.2008 at 09:33AM PDT, ID: 22703801

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.13.2008 at 09:35AM PDT, ID: 22703812

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.13.2008 at 09:59AM PDT, ID: 22704034

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.13.2008 at 10:02AM PDT, ID: 22704050

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.13.2008 at 10:31AM PDT, ID: 22704298

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.13.2008 at 10:49AM PDT, ID: 22704498

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.13.2008 at 10:51AM PDT, ID: 22704514

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.13.2008 at 11:04AM PDT, ID: 22704643

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.13.2008 at 11:07AM PDT, ID: 22704680

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-42 / EE_QW_2_20070628