Subject | RE: [firebird-support] Stored procedure to return multiple rows in a single string |
---|---|
Author | Sasha Matijasic |
Post date | 2008-02-26T21:57:14Z |
> Sasha told me in our previous conversation that it would be possible toSomething like this:
> write a stored procedure that joins strings from multiple table rows
> into a list and returns it as a string.
>
> So
> row1
> row2
> row3
>
> would look like
> "row1, row2, row3" in a single string. The stored procedure would be
> called in a main select query.
>
> Unfortunately I'm not a master of stored procedures, and I can't seem
> to find enough info on Google on how to create such a listing
> procedure.
>
> Could someone point me in the right direction with an example?
>
create procedure list_names
returns (nameid integer, name varchar(20), members varchar(200) )
as
declare variable temp_member varchar(20);
begin
for
select nameid, name from nms
into :nameid, :name do
begin
members = '';
for
select membername from members
where nameid = :nameid
into :temp_member do
members = members || iif(members = '', '', ', ') || coalesce(:temp_member, '');
suspend;
end
end^
I haven't really tested it but from this you will be able to make it work.
Sasha