Subject Re: [ib-support] Not in query
Author Helen Borrie
At 08:47 PM 30-06-01 -0800, you wrote:
>Can anyone provide an example of SQL syntax that would compare
>the primary index of one table to another to determine whether or
>not a value in one table exists in the other, and if not then
>insert it?


Not in one statement - it can be done with a simple stored procedure, though.

create procedure conditional_insert(var1 integer, var2 whatever,...)
as
begin
if (not(exists(select pk_table2 from table2 where pk_table2= :var1))) then
insert into table2(col1, col2, ...)
values(:var1, :var2,.....);
end

Cheers,
Helen

All for Open and Open for All
InterBase Developer Initiative ยท http://www.interbase2000.org
_______________________________________________________