Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old August 12th, 2003, 09:58 PM
milesfeinberg milesfeinberg is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 1 milesfeinberg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Trouble using fn_get_sql to capture table changes

I created an trigger (on insert and update) on a table that uses the new fn_get_sql function that comes with SQL Server 2000 SP3. I use it to record who performed what transaction and when they did it. It looks like this:

--------------------------------
CREATE TRIGGER Update_Last_Modified ON [dbo].[MYTABLENAME]
FOR UPDATE, INSERT
AS
BEGIN
SET NOCOUNT ON
DBCC TRACEON (2861)

DECLARE @Qry nvarchar(4000)


DECLARE @handle binary(20)

SELECT @handle = sql_handle
FROM master..sysprocesses
WHERE spid = @@SPID

SET @QRY = (SELECT CONVERT(nvarchar(4000), [text]) FROM ::fn_get_sql(@handle))

UPDATE MYTABLENAME
SET DATE_LAST_MODIFIED = GETDATE(),
LAST_COMMAND = @QRY,
LAST_USER = SYSTEM_USER
FROM inserted
WHERE MYTABLENAME.UID= Inserted.UID
END

----------------------------------

It was previously coded to use DBCC INPUTBUFFER, and it worked fine, but I was limited to the first 255 characters of the command, which prevented me from seeing the critical parts, like the where clause! When I modified the trigger to use fn_get_sql, all I ever see is the entire text of the create trigger command. Maybe I should use an entirely different approach. I'm open to ideas.

Thanks very much in advance for your help!

Miles

Reply With Quote
  #2  
Old December 9th, 2003, 11:41 AM
GT3Dev GT3Dev is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 1 GT3Dev User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Miles,

I have the same problem with fn_get_sql and I don't have a solution.

However, I would like to know how exactly you were able to use DBCC INPUTBUFFER to record the user's last stmt.

Thanks.

--Mark

Last edited by GT3Dev : December 9th, 2003 at 11:44 AM.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > Trouble using fn_get_sql to capture table changes


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT