Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trigger returns empty record set

Status
Not open for further replies.

destinyml

ISP
Apr 27, 2004
27
DK
Hi

I have made a trigger that fires when deleting rows. However it returns an empty recordset, and it is not supposed to. How do I change that?

CREATE TRIGGER [Log_Delete_Definition_Source] ON [dbo].[Definition_Source]
FOR DELETE
AS

SET NOCOUNT ON

DECLARE @concept_identifier int,
@page varchar (15),
@source_identifier varchar (20),
@language_symbol char (2),
@note nvarchar (1000)

DECLARE definition_source_cursor CURSOR FOR SELECT concept_identifier, page, source_identifier, language_symbol FROM Deleted INNER JOIN Definition ON Deleted.definition_identifier = Definition.definition_identifier

OPEN definition_source_cursor

-- Perform the first fetch.
FETCH NEXT FROM definition_source_cursor INTO @concept_identifier, @page, @source_identifier, @language_symbol

-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN
-- This is executed as long as the previous fetch succeeds.
SET @note = 'Source deleted for ' + @language_symbol + ' definition.' + CHAR(13) + 'Source: ' + @source_identifier
IF @page <> ''
BEGIN
SET @note = @note + CHAR(13) + 'Page: ' + @page
END

EXEC Trigger_Insert_Concept_Terminology_Management_Transaction 6, @concept_identifier, @note

FETCH NEXT FROM definition_source_cursor
END

CLOSE definition_source_cursor
DEALLOCATE definition_source_cursor
 
In the second FETCH statement (inside the cursor loop), you need to duplicate the first one, ie add the INTO <variables> stuff.

--James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top