Subject Re: [firebird-support] multiple rows in singleton select
Author Martijn Tonies
Hi,

> I am getting following error when executing the SP from .Net
>
> "multiple rows in singleton select"
>
> But, the SP doesn't contain any select (from table) statement. Just

Ahum... (see below)

> few Insert and two statements like -
>
> sp:
>
> DECLARE VARIABLE prodid INTEGER;
> DECLARE VARIABLE ProductID INTEGER;
> BEGIN
> INSERT INTO products ..
>
> SELECT GEN_ID("MY_GENERATOR" , 0) FROM products INTO :prodid;

Aha! What do you call the above then? :-)

Assuming multiple rows in PRODUCTS, you're selecting multiple rows
in a singleton select (INTO :prodid). In short, don't do this - but change
it like this:

prodid = gen_id(mygenerator, 1);
insert into products (...) values (:prodid, ...)



> IF (:prodid IS NOT NULL) THEN
> BEGIN
> INSERT INTO A ..
> INSERT INTO B ..
> INSERT INTO C ..
> END
>
> SELECT GEN_ID("MY_GENERATOR" , 0) FROM products INTO :ProductID;
> SUSPEND;
> END
>
>
> Is this because of select gen_id(..)?

Well, yes. You don't need to SELECT GEN_ID either in a procedure.

With regards,

Martijn Tonies
Database Workbench - the developer tool for InterBase & Firebird
Upscene Productions
http://www.upscene.com