Subject RE: [firebird-support] How can a stored procedure construct a string made up of multiple row data?
Author Alan McDonald
> Dear forum members,
>
> I have a column of unique cities. I would like to create a
> procedure, when executed returns a varchar containing all cities
> enclosed in brackets, for example:
>
> [Arlington][Beaumont][Chicago]
>
>
>
> CREATE PROCEDURE NEW_PROCEDURE
> returns (
> cities varchar(2000),
> as
> begin
> select city_tbl.city from city_tbl into :cities;
> suspend;
> end^
>
>
> In my procedure I get a singleton select error. I guess that if I
> knew how to traverse each record within the procedure, would be able
> to concatenate each city into the varchar.
>
> Thank you

> CREATE PROCEDURE NEW_PROCEDURE
> returns (
> cities varchar(2000),
> as
DECLARE tmpcity VARCHAR(50);
> begin
cities = '';
> FOR select city_tbl.city from city_tbl into :TMPCITY DO BEGIN
cities = :cities||'['||:tmpcity||']';
END
exit;
> end^

Alan
PS this is terrible design.