nathanharcup
MIS
Hi All,
I have created the below trigger but cannot figure out why the delete statment does not work? all other statments work as expected.
If i change the variable to the actual value it does work..
Thanks
alter TRIGGER [tr_sitelocation] ON dbo.usr_refsitelocation
FOR INSERT, UPDATE
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @usr_sitelocation varchar(255),
@usr_guid uniqueidentifier,
@usr_deleted int
-- Insert statements for trigger here
Select @usr_sitelocation = usr_sitelocation,
@usr_guid = usr_guid,
@usr_deleted = usr_deleted
From Inserted
--Delete from the departments table if the entry has been deleted
If @usr_deleted = 1
begin
update set [Location] = NULL where EU_Location = @usr_sitelocation
*************does not run ***************
delete from [Location] where [Location] = @usr_sitelocation
*************does not run ***************
end
if not exists (select Location from [Location] where Location = @usr_sitelocation)
begin
insert into [Location values] (@usr_sitelocation)
end
END
GO
I have created the below trigger but cannot figure out why the delete statment does not work? all other statments work as expected.
If i change the variable to the actual value it does work..
Thanks
alter TRIGGER [tr_sitelocation] ON dbo.usr_refsitelocation
FOR INSERT, UPDATE
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @usr_sitelocation varchar(255),
@usr_guid uniqueidentifier,
@usr_deleted int
-- Insert statements for trigger here
Select @usr_sitelocation = usr_sitelocation,
@usr_guid = usr_guid,
@usr_deleted = usr_deleted
From Inserted
--Delete from the departments table if the entry has been deleted
If @usr_deleted = 1
begin
update set [Location] = NULL where EU_Location = @usr_sitelocation
*************does not run ***************
delete from [Location] where [Location] = @usr_sitelocation
*************does not run ***************
end
if not exists (select Location from [Location] where Location = @usr_sitelocation)
begin
insert into [Location values] (@usr_sitelocation)
end
END
GO