Subject | Re: Implode |
---|---|
Author | anzejbecan |
Post date | 2004-01-27T11:33:35Z |
> AFAIK, you could do something like that with Firebird 1.5My dear, I'm so happy to find out what I want. With of you all. Here
> I'm not sure what is the exact keyword and syntax for it, I guess
> someone else will help you...
is the procedure Implode:
ALTER PROCEDURE IMPLODE (
INPUTSTR VARCHAR(1000),
SEPARATOR VARCHAR(10))
RETURNS (
OUTPUTSTR VARCHAR(1000))
AS
DECLARE VARIABLE FIRSTONE SMALLINT;
DECLARE VARIABLE TEMP VARCHAR(100);
begin
OUTPUTSTR = '';
FIRSTONE = 0;
for EXECUTE STATEMENT :INPUTSTR into :TEMP do
begin
if (TEMP is not null) then begin
if (FIRSTONE = 0) then FIRSTONE = 1;
else OUTPUTSTR = OUTPUTSTR || SEPARATOR;
OUTPUTSTR = OUTPUTSTR||TEMP;
end
end
suspend;
end
How to use it:
select * from implode('select name from people', ', ');
... or any othe more complicated query.
Thanks everyone!