Click here to Skip to main content
15,886,025 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi friends,

I am trying to update a value in a table while inserting..
I am using this trigger...

SQL
CREATE TRIGGER add_auth_code
   ON  dbo.aspnet_Users
   AFTER INSERT
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
    authcode = "54464966464446";
    -- Insert statements for trigger here

END


I want to set an authcode to the currently inserting column,,, How can I update it,,, Please somebody help me....
Posted

1 solution

Hi Please refer below example , it may help you, you have to use key columns of table in join with Inserted Table. so here you can know what is id or userid of newly inserted record. and then you can do update on it.

sample code 4 U:

CREATE TRIGGER add_auth_code
ON dbo.aspnet_Users
AFTER INSERT
AS
BEGIN

SET NOCOUNT ON;
UPDATE p
SET authcode = "54464966464446"
FROM dbo.Products AS p
INNER JOIN inserted AS i
ON p.ProductID = i.ProductID;


END

Regards
Mubin
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900