Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Syntax qustion when creating TEMP table on the fly
Message
From
17/04/2003 11:15:35
 
 
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Miscellaneous
Thread ID:
00778391
Message ID:
00778872
Views:
14
Hi, Michael...

In a nutshell, I'm trying to do the following any time an UPDATE is done...

- Take the INSERTED and DELETED tables in an UPDATE trigger, and 'pass' them on to a stored proc.

- The stored proc [a generic one] will analyze the INSERTED and UPDATED tables, and will post to an application audit trail log table as necessary.

Because INSERTED and DELETED are only visible inside a trigger [at least that's my understanding], and since I can't find a way to 'pass' them to a stored proc....I was initially doing a...

SELECT * INTO #TEMPINSERTED FROM INSERTED
SELECT * INTO #TEMPDELETED FROM DELETED


...and then the stored proc that I would call at the end of the trigger [called LOGCHANGES] would read #TEMPINSERTED and #TEMPDELETED.

There were two problems with that...first was our DBA freaked at the notion of a SELECT *, even on a one row system table. The second problem, more a practical one, is that a few columns in our DB are TEXT and IMAGE...and those can't be used in a SELECT * FROM INSERTED [you wind up getting an error]. The list of columns for every table that we wish to 'log' are stored in an application data dictionary, so I want to read out of that application DD and dynamically build a [pardon the VFP syntax]

SELECT &cFieldList INTO #TempInserted FROM Inserted

Since you can only do this with EXEC, and since EXEC blows away any temp table that's referenced in the statement....that's when I posted my question.

The response I received from Roman seems to work. Everything I'm doing to make this work seems like a fair amount of gymnastics, but it does seem to work. I was able to simulate 50 concurrent updates this morning, with no real performance impact.

So for now, my problem is solved...but anything that you can think of to simplify or streamline this would be great.

Thanks,
Kevin
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform