Subject Re: SQL statement with multiply function
Author Adam
--- In firebird-support@yahoogroups.com, "majstoru" <majstoru@...>
wrote:
>
> Hi,
>
> I have a data in table (example)
> Table1
> id name qty
> 1 Article 1 3
> 2 Article 2 2
> 3 Article 3 1
>
> is there any solution if Firebird that I can write SQL statement
which
> will return this table in format
> Table2
> id name
> 1 Article 1
> 1 Article 1
> 1 Article 1
> 2 Article 2
> 2 Article 2
> 3 Article 3
>
> whih mean that I get result table where avery record is multiplied
> with qty, or how many rows are in resultset, that is represent a
qty
> column in table1.
>
> Thanks for help!
>

A stored procedure can output the article and id however many times
qty represents:


Create procedure SP_MultiplyArticles
returns
(
id integer,
name varchar(50)
)
as
declare variable qty integer;
declare variable i integer;
begin
for select id, name, qty
from articles
into :id, :name, :qty
do
begin
i = 1;
while (:i <= :qty) do
begin
suspend;
i := :i + 1;
end
end
end
^

To run it.

select *
from SP_MultiplyArticles;

It may be quicker to do it from the client (network traffic etc) if
there are large qty numbers.

Adam