Subject Re: Multiple Rows Error in Stored Procedure
Author Adam
Michael,

It is not about whether or not the query returns multiple records, but
whether or not there is the potential to have multiple records. Keep
in mind that the Stored Procedure needs to operate even after you fill
the table with whatever data it accepts. If it is technically possible
to put data into the table that will cause this query to return
multiple records, then that error is appropriate.

I do not know whether firebird will accept the query if the where
clause contains a unique value such as the primary key of the table. I
doubt it would, nor should it IMO. As a developer, you want to
deliberately specify that you are only expecting 1 record. It would be
like saying i+=1 in C. You can do it, but the risk of accidentally
typing i=+1 is so high, and locating it is a pain. Again, IMO you
should deliberately tell Firebird what to do if it encounters more
than one record even if you believe it is impossible.

Try this sort of statement. This guarantees a singleton result
regardless of the where clause (even if it is empty).

Select First 1 Field
From Table
where Value = InputValue
into :Output Value




--- In firebird-support@yahoogroups.com, "hopemedmike"
<michael.suarez@h...> wrote:
>
> I am getting the error "Multiple rows in singleton select" when i run
> my stored procedure.
>
> The stored procedure has a select statement
> Select Field from Table where Value= InputValue into OutputValue.
>
> Now i know what the error means. If the field has more than one
> record where it is equal to the input value, it will give you that
> error.
>
> However, looking at the data, i know for sure there is only 1 record
> for each value of this field.
>
> In fact, I copied the table, and had the SP select from the copied
> one. If the copied table had no records, no error. If it had just one
> record, i get the error.
>
> What might be the cause of the error?