Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Tables as Stored Proc Parms

Author  Topic 

mickers
Starting Member

2 Posts

Posted - 2005-08-21 : 22:54:13
Hi,
I am trying to pass a table to a stored proc and can't get it to work. Basically I want something like this to work:
CREATE PROCEDURE dbo.ps_InsUpd
@insertedTable table,
@deletedTable table
AS
select * into #inserted from @insertedTable
select * into #deleted from @deletedTable

The tables are the special tables inserted and deleted from the trigger for for insert, update, delete. Can you provide me the syntax to do this?

Thanks,
Michael


--
21st Century Technologies, Inc.
http://www.21stsoft.com
(303) 744-2178 Voice/Fax
"Any sufficiently advanced technology is indistinguishable from magic."
Arthur C. Clark, The Lost Worlds of 2001
-------------------------------------------

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2005-08-21 : 23:10:48
sorry, you can't use tables as input parameters to a stored procedure. Anyway, once the trigger code has finished executing, the tables are out of scope. You can however create temp tables in the trigger itself and populate them based on the inserted and deleted tables. What are you trying to do?

Be One with the Optimizer
TG
Go to Top of Page

mickers
Starting Member

2 Posts

Posted - 2005-08-23 : 20:32:40
I am auditing multiple tables. The audit is started in the insert, update, delete triggers for each of the tables we want to audit. Within each of these triggers I am calling this stored proc and want to pass the tables.

The reason I am using the stored proc is so I can have one set of code that performs all of the aidit code, and if I want to change it, all changes can be made in one place.

I have the code working as a trigger, but now I want to move it to the stored proc.

--
21st Century Technologies, Inc.
http://www.21stsoft.com
(303) 744-2178 Voice/Fax
"Any sufficiently advanced technology is indistinguishable from magic."
Arthur C. Clark, The Lost Worlds of 2001
-------------------------------------------

Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2005-08-24 : 09:49:44
Hi again Michael,

Were you planning on using one audit table or one audit table per table? There has been a lot of discussion about using a single table to capture audit info for multiple tables. Here's 3 of them: (I searched on "Audit table")

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=38604
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=52356
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=41090

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -