Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Reading uncommitted data
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01426495
Message ID:
01426513
Views:
40
>>The Insert statement looks like this:
><snip>
>
>>The only field of interest is fkFaultsLog which should be the parent record of an opened fault (when it is being closed which is determined by i.SetFlag = 0) the two stored procedures getClearedEventFaultsLogPK (Horrible name I came up on a Sunday when I was very tired) and getClearedEvent() both seem to work fine when I ran them from outside, but they always return null from the trigger, that is why I thought it was a problem with the commit
>
>You cannot use stored procedures this way. You should change them to UDFs.

Sorry Sergey, I misnamed them, they are actually two scalar functions, my bad.

Also I forgot to post the code for the important one, as it is the one that uses the same table that is being inserted
USE [TVM]
GO
/****** Object:  UserDefinedFunction [dbo].[getClearedEventFaultsLogPK]    Script Date: 09/28/2009 12:18:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		RAN02
-- Create date: 2009-09-27
-- Description:	Returns the PK from FaultsLog for an event that was cleared
-- =============================================
ALTER FUNCTION [dbo].[getClearedEventFaultsLogPK] 
(
	@iEventPK int,
	@iDevicePK int
)
RETURNS int
AS
BEGIN
	-- Declare the return variable here
	DECLARE @iFKFaultsLog int

	-- Add the T-SQL statements to compute the return value here
	SET @iFKFaultsLog =	(
							SELECT TOP 1
										FL.PK
								FROM	TVM.dbo.FaultsLog FL
								JOIN	TVM.dbo.EventsLog EL ON FL.fkEventsLog = EL.PK
								WHERE	EL.fkEventDefinitions = @iEventPK and EL.SetFlag = 1 and FL.fkDevices = @iDevicePK
								ORDER	BY EL.Created DESC
						)

	-- Return the result of the function
	RETURN @iFKFaultsLog

END
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform