Subject Re: [firebird-support] Simple trigger task
Author peter@cyionics.com
Hi Yves

I too was pretty new to stored procedures, but I found by using database workbench all the hard work was done for me and in addition you can test you procedures in a friendly environment.

I'm still learning lost but I found workbench absolutely invaluable, it also helps with creating the triggers etc.
I can't recommend it enough !.

Rgds

Peter

simple example of one of the stored procedures I use

/*
Procedure:

Author : PJC
Date : 14/08/2003
Purpose : alter status of pin to sold
Params
------
<param> : INDEX_ID unique key-id to pin
*/
begin
/* code */
RETURN_VAL = 0;

IF (EXISTS ( SELECT ID FROM PINS WHERE ID = :INDEX_ID and STATUS = 1 )) THEN
BEGIN
UPDATE PINS SET
STATUS = 4,
STATUS_CHANGED = 'NOW',
DATE_SOLD = 'NOW'

WHERE ID = :INDEX_ID;
RETURN_VAL = :INDEX_ID;

END




end


----- Original Message -----
From: Yves Glodt
To: firebird-support@yahoogroups.com
Sent: Sunday, November 16, 2003 2:35 PM
Subject: [firebird-support] Simple trigger task


Hi,

I never used triggers/stored procedures, but I think the moment to start
with has come... See this table:

CREATE TABLE WT_PERS (
IPN INTEGER NOT NULL,
PERS_BDG VARCHAR(20),
PERS_NUMBER VARCHAR(20),
PERS_NAME VARCHAR(50),
etc ....
PRIMARY KEY (IPN)
);

When a new person is inserted, the field PERS_NUMBER is not included in
the insert statement.

What I wanna do is, after an insert has been performed, the field
PERS_NUMBER should automatically get the last (highest) used
PERS_NUMBER incremented by 1

So I guess an after-insert-trigger that calls a stored procedure which
updates the PERS_NUMBER would be the way to go.

How would such a trigger/stored proc look like?

Thank you and best regards,
Yves Glodt


--
Linux 2.4.22-1-k7 #1 Sat Sep 6 02:13:04 EST 2003 i686
15:18:48 up 9 min, 1 user, load average: 0.14, 0.21, 0.15


Yahoo! Groups Sponsor
ADVERTISEMENT




To unsubscribe from this group, send an email to:
firebird-support-unsubscribe@yahoogroups.com



Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.


[Non-text portions of this message have been removed]