Click to See Complete Forum and Search --> : Confused with Trigger


Exceter
August 11th, 2003, 12:07 AM
How to set the variable value from the "inserted"?
Here I want to insert value inserted into one table, insert another tables too.
but I have error in red line,
May be there are other ways to do that?

CREATE TRIGGER GeneralInsert
ON PersonalFile
FOR INSERT
AS
BEGIN
DECLARE @PF varchar(10)
SELECT PersonalFile
FROM inserted i
SET @PF = i.PersonalFile
Insert into Table1(PersonalFile)
VALUES(@PF)
Insert into Table2(PersonalFile)
VALUES(@PF)
Insert into Table3(PersonalFile)
VALUES(@PF)
END

womalley
August 15th, 2003, 10:19 AM
Originally posted by Exceter
How to set the variable value from the "inserted"?
Here I want to insert value inserted into one table, insert another tables too.
but I have error in red line,
May be there are other ways to do that?

CREATE TRIGGER GeneralInsert
ON PersonalFile
FOR INSERT
AS
BEGIN
DECLARE @PF varchar(10)
SELECT PersonalFile
FROM inserted i
SET @PF = i.PersonalFile
Insert into Table1(PersonalFile)
VALUES(@PF)
Insert into Table2(PersonalFile)
VALUES(@PF)
Insert into Table3(PersonalFile)
VALUES(@PF)
END
-- first set your variable
SET @PF = ''
-- now assign the value, careful though. If there is more then one @PF will keep appending the values to its self.

SELECT @PF = @PF + PersonalFile FROM Inserted

Now just to test.
PRINT @PF


this should get you close.

Will