=> Trigger to copy duplicate rows into a new table where val >26
From: Rhonda Fischer (anonymous_at_discussions.microsoft.com)
Date: 04/07/04
- Next message: Vishal Parkar: "Re: Number to Date."
- Previous message: anonymous_at_discussions.microsoft.com: "Dynamic query...problem"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 7 Apr 2004 08:06:09 -0700
Hello,
I am attempting to create the following trigger:
=============================================================================
CREATE TRIGGER trgLoadExceedTrlCapacity ON [tblOrders]
FOR INSERT, UPDATE, DELETE
AS
/* The purpose of this trigger is to ensure that no entries have in excess of 26 pallet loads */
/* The Supermarket may order more than 26 loads of produce but the Trailer can only manage 26 loads */
/* so extra lines are inserted into the new table tblSplitOrders with a maximum of 26 loads */
/* and an extra line for the remaining pallets */
DECLARE @NumOfLoads int,
@LoadsRemainder int,
@CountSplit int,
@Cnt int
/* Number of Loads from tblOrders saved to variable */
@NumOfLoads = NumOfLoads
@LoadsRemainder = 0
@CountSplit = 0
@Cnt = 0
/* Determine if there are more than 26 loads */
@LoadsRemainder = @NumOfLoads / 26
if (@LoadsRemainder >= 1) then
while (@LoadsRemainder >= 1)
@NumOfLoads = @NumOfLoads - 26
@CountSplit = @CountSplit + 1
@LoadsRemainder = @NumOfLoads / 26
end
for @Cnt = 0 to (@CountSplit - 1)
INSERT INTO tblSplitOrders (DeliveryID, CollectionID, TempID, OrderDate, NumOfLoads)
SELECT (DeliveryID, CollectionID, TempID, OrderDate, 26) FROM tblOrders
end
INSERT INTO tblSplitOrders (DeliveryID, CollectionID, TempID, OrderDate, NumOfLoads)
SELECT (DeliveryID, CollectionID, TempID, OrderDate, @NumOfLoads) FROM tblOrders
else
INSERT INTO tblSplitOrders (DeliveryID, CollectionID, TempID, OrderDate, NumOfLoads)
SELECT (DeliveryID, CollectionID, TempID, OrderDate, @NumOfLoads) FROM tblOrders
end if
END
==============================================================================
The error message I receive:
Error 170: Line 14: Incorrect syntax near '@NumOfLoads'
Incorrect syntax near the keyword 'then'
Line 25: Incorrect syntax near '@NumOfLoads'
Line 32: Incorrect syntax near ','
Line 36: Incorrect syntax near ','
Line 41: Incorrect syntax near ','
I'm not sure if my trigger is the most effective means to achieve my objective and if this trigger
will successfully copy over a single line with up to and including 26 pallets and will copy
lines with a maximum of 26 pallets multiple times until the smallest remainder is copied in as the
last entry with the same DeliveryID, CollectionID, TempID, OrderDate for each entry.
There is a unique incrementing ID in the tblSplitOrders table.
Do you have any suggestions that might assist me.
Thank you kindly
Rhonda
- Next message: Vishal Parkar: "Re: Number to Date."
- Previous message: anonymous_at_discussions.microsoft.com: "Dynamic query...problem"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
- Re: MoveAfterReturn is tricking me.
... The argument Target in the Worksheet_Change event tells you what cell ... >
I've got the first column of my worksheet checking to see if the ... > first character
of the typed entry is a string or a number. ... > Because of the way that the event
trigger seems to work, ... (microsoft.public.excel.programming) - Re: Create a Trigger for an existing View
... INNER JOIN DEMO_ORDERS ... If user X with the USER_ID 2 will complete a new
order my trigger must ... updating trigger, but the actuator for the trigger is
an "insert into" ... I must insert the new entry of DEMO_ORDERS over a trigger into my
new ... (comp.databases.oracle.server) - Re: Form control
... I don't want to track dates I just want upon entry of ... >> trigger
the selection of one of the radion buttons ... >> in my options group shown
at the top of my form. ... (microsoft.public.access.formscoding) - Re: Create a Trigger for an existing View
... INNER JOIN DEMO_ORDERS ... If user X with the USER_ID 2 will complete a new
order my trigger must ... updating trigger, but the actuator for the trigger is
an "insert into" ... I must insert the new entry of DEMO_ORDERS over a trigger into my
new ... (comp.databases.oracle.server) - Re: Create a Trigger for an existing View
... INNER JOIN DEMO_ORDERS ... If user X with the USER_ID 2 will complete a new
order my trigger must ... I must insert the new entry of DEMO_ORDERS over a trigger
into my new ... and when a transaction starts. ... (comp.databases.oracle.server)