Subject Re: Union in firebird
Author Adam
--- In firebird-support@yahoogroups.com, "didinh2000"
<didinh2000@y...> wrote:
> Why this statement doesn't work in firebird 1.5 ?
>
> insert into employee (emp_id,emp_name,emp_zip,emp_loan)
> select emp_id,'Name xxx','0001',emp_loan from loan_mtd
> union
> select emp_id,'Name xxx','0001',emp_loan from loan_ytd
>

Pretty simple, Firebird doesn't support that syntax.

> or you've suggest for this problem ?

A Stored Procedure could easily do it. You could pass in the employee
name and zip code as parameters if you liked.

...
BEGIN
FOR select emp_id,emp_loan from loan_mtd
union
select emp_id,emp_loan from loan_ytd
INTO :EMP_ID, :EMP_LOAN
DO
BEGIN
insert into employee (emp_id,emp_name,emp_zip,emp_loan) values
(:emp_id,'Name xxx','0001',:emp_loan);
END;
END;

But I am not too sure if your original logic would work anyway,
because I am guessing that loan_mtd and loan_ytd would contain
records relevant to other customers (so you would want to include a
where condition)

Adam