Subject | Re: [ib-support] How do I test for a value before an INSERT? |
---|---|
Author | Ernesto Cullen |
Post date | 2002-06-05T13:14:41Z |
You can make a Stored Procedure which should take all the values as input
parameters and issue the inserts
for example, using your definitions (guessing the datatypes)
CREATE PROCEDURE spMultipleInsert (
emp_id integer,
fname varchar(30),
lname varchar(30),
job_Code integer,
job_title varchar(30))
AS
Declare variable locCode integer;
BEGIN
select pk_job
from t_job_title
where pk_job= :job_code
into :locCode;
if (locCode is null) then
insert into t_job_title (pk_job, job_title)
values (:job_code, :job_title);
insert into t_emp_info (pk_emp_id, fk_job, fname, lname)
values (:emp_id, :job_code, :fname, :lname);
END
The first SELECT looks for your job code; if not found, it is inserted.
Hope this helps
Ernesto Cullen
parameters and issue the inserts
for example, using your definitions (guessing the datatypes)
CREATE PROCEDURE spMultipleInsert (
emp_id integer,
fname varchar(30),
lname varchar(30),
job_Code integer,
job_title varchar(30))
AS
Declare variable locCode integer;
BEGIN
select pk_job
from t_job_title
where pk_job= :job_code
into :locCode;
if (locCode is null) then
insert into t_job_title (pk_job, job_title)
values (:job_code, :job_title);
insert into t_emp_info (pk_emp_id, fk_job, fname, lname)
values (:emp_id, :job_code, :fname, :lname);
END
The first SELECT looks for your job code; if not found, it is inserted.
Hope this helps
Ernesto Cullen
----- Original Message -----
From: "Derek Basch" <dbasch@...>
To: <ib-support@yahoogroups.com>
Sent: Wednesday, June 05, 2002 4:33 AM
Subject: [ib-support] How do I test for a value before an INSERT?
> Hi,
> Im new to SQL and I have created several tables and
> would like to be able to INSERT to several of them at
> the same time. I cant seem to find any
> examples/techniques for breaking apart records and
> inserting into multiple tables.
>
> For example:
> ---t_emp_info---
> pk_emp_id
> fk_job
> fname
> lname
>
> ---t_job_title---
> pk_job
> job_title
>
> Now, what if I want to add a new employee and a job
> title? I will obviously need 2 INSERT's, right? I
> would like to insert the emp_info and then the
> job_title ONLY if the title doesnt already exist in
> the t_job_title table. Can I do this?
> Thanks,
> Derek Basch
>