Click here to Skip to main content
15,890,717 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hallo,

I want to write a trigger that updates two other tables before a delete operation of one element is executed. However I get an error message: Invalid column name. Can someone plese help me?

Thanks

CREATE TRIGGER [tbl_a].[tbl_a_trd] ON [tbl_a].[]
WITH EXECUTE AS CALLER
FOR DELETE
AS
DECLARE @number as int
DECLARE @maxint as int
DECLARE @mask as int
DECLARE @client as int
DECLARE @rc as int
SET @rc = @@ROWCOUNT;
IF @rc = 0 
RETURN;
IF @rc = 1
BEGIN

  set @number = (select number from deleted);
  set @maxint = 2147483647 ;
  set @mask = maxint - number;
  set @client = (select client from deleted);

  
  update tbl_b set flag = (flag & mask) where client = @client;
  
  update tbl_c set flag = (flag & mask) where client = @client;
  
END
GO
Posted
Comments
Bala Selvanayagam 2-Nov-11 14:02pm    
What you are trying to achieve by (flag & mask) ? in the update statement
chris085 2-Nov-11 14:05pm    
i want to do a bitwise and
Bala Selvanayagam 2-Nov-11 14:24pm    
Just posted an answer, please have a look and let me know wehther helps

1 solution

Replace
set @mask = maxint - number;

with
set @mask = @maxint - @number;



also

Replace

SQL
update tbl_b set flag = (flag & mask) where client = @client;

  update tbl_c set flag = (flag & mask) where client = @client



with

SQL
update tbl_b set flag = (flag & @mask) where client = @client;

  update tbl_c set flag = (flag & @mask) where client = @client;




This should work
 
Share this answer
 
v2
Comments
chris085 2-Nov-11 14:59pm    
That's it. Thanks a lot
Bala Selvanayagam 2-Nov-11 15:18pm    
good to hear

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