Answered by:
insert trigger

Question
-
Hello,
When i attempt the following trigger on Insert, in inserts all the fields where i assigned a value but it is not insrting the "INSERTED", it shows as null, does any one have an idea on what i am doing wrong?
Thank yoU
ALTER TRIGGER INSERTTEST ON TESTTABLE FOR INSERT AS INSERT INTO OTHERTABLE(DATE,ID,NAME,DATE_GIVEN) SELECT INSERTED.DATE,DUMMY_ID = '',INSERTED.FIRSTNAME, THEDATE= CAST (CONVERT(varchar,INSERTED.DATE,112) as INT) FROM INSERTED WHERE SAVEFLAG = '100'
Tuesday, December 21, 2010 9:10 PM
Answers
-
Hello,
I found the problem hehehe, this is the right code
ALTER TRIGGER INSERTTEST ON TESTTABLE FOR UPDATE *** AS INSERT INTO OTHERTABLE(DATE,ID,NAME,DATE_GIVEN) SELECT INSERTED.DATE,DUMMY_ID = '',INSERTED.FIRSTNAME, THEDATE= CAST (CONVERT(varchar,INSERTED.DATE,112) as INT) FROM INSERTED WHERE SAVEFLAG = '100'
- Marked as answer by EROD81 Tuesday, December 21, 2010 9:54 PM
Tuesday, December 21, 2010 9:54 PM
All replies
-
Hi, I tested your trigger and It worked, can you verify if the value inserted of SAVEFLAG is really '100' ?
Best regardsTuesday, December 21, 2010 9:31 PM -
Hello Badi,
Well the thing is that i am progrssivly saving that flag (updating the table) until it reachs 100, so i am thinking that it is firing right after i do the first insert... but i wanted to insert into the other table on the last update of the main table..
Regards
Tuesday, December 21, 2010 9:50 PM -
Hello,
I found the problem hehehe, this is the right code
ALTER TRIGGER INSERTTEST ON TESTTABLE FOR UPDATE *** AS INSERT INTO OTHERTABLE(DATE,ID,NAME,DATE_GIVEN) SELECT INSERTED.DATE,DUMMY_ID = '',INSERTED.FIRSTNAME, THEDATE= CAST (CONVERT(varchar,INSERTED.DATE,112) as INT) FROM INSERTED WHERE SAVEFLAG = '100'
- Marked as answer by EROD81 Tuesday, December 21, 2010 9:54 PM
Tuesday, December 21, 2010 9:54 PM