SQL Server Trigger Exec Deleted Table
In SQL server 2000, in a trigger
When i use the Exec(), it cannot find the deleted table. Why?
EXECUTE ('Insert into TestTable Select PatientID from Deleted')
Web Development
In SQL server 2000, in a trigger
When i use the Exec(), it cannot find the deleted table. Why?
EXECUTE ('Insert into TestTable Select PatientID from Deleted')
by surinderx
Dear
You must log on to akadia.com
Lv
Surinder Kapoor
Sr. EDP Incharge
Vishal Group of Companies
by dmarro
by mark_t
I got the following to work, not sure if its of use or what your looking for, still you might be able
to adapt it.
Run this script, it'll create 2 tables with a trigger on 1, also included is a stored procedure.
The table/stored procedure namesare a bit confusing, but it should be easy to follow anyhow.
------------------------------------------------------------------------------------------------------------
CREATE TABLE [dbo].[tbl_Temp] (
[tablename] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[description] [char] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[tbl_Temp_Audit] (
[triggertable] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[description] [char] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE sp_Insert_TriggerTable
@TriggerTable char(30),
@Description char(50)
AS
BEGIN
declare @insertstring char(200)
select @insertstring = 'insert into ' + @TriggerTable + ' VALUES (' + char(39) + @TriggerTable + char(39) + ',' + char(39) + @Description + char(39)+ ')'
EXECUTE(@insertstring)
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
------------------------------------------------------------------------------------------------------------
From iSQL run
insert into tbl_temp values ('tbl_temp_audit','Test 1')
The trigger for tbl_temp should insert a record into tbl_temp_audit using the stored procedure.
See if this is any good, let me know either way.
Mark
by dmarro
by dmarro
by dmarro
This discussion is closed to new replies.
Sort by Trending