Subject Re: How to make this (kind of a sort) inside a stored procedure?
Author kurei_spin
Thanks for helping! Worked perfectly!!!

bye!

--- In firebird-support@yahoogroups.com, "Ivan Prenosil"
<Ivan.Prenosil@...> wrote:
>
> > Hi people! I've been trying to make a stored procedure where I
have
> > to move some strings inside an array. The first problem is that
I
> > can't use an array inside a stored procedure, right?
>
> Isn't CHAR(5) the same as _array_ of 5 characters ?
>
>
> > So, I had to
> > create 5 varchar variables. These variables may have only two
> > values: 'T' or 'S'. And I want to make the 'T' values to be
together
> > in the order. Here's my code:
> ...
> > /*IF YOU TAKE A LOOK YOU'LL SEE THAT AFTER THAT I HAVE THE
> > FOLLOWING:*/
> > /*('T','T','S','T','S')*/
> > /*AND I WANT IT TO BE LIKE THIS:*/
> > /*('T','T','T','S','S')*/
> > /*SO, THE CODE MUST THROW THE 'S' TO THE RIGHT AND THE 'T' TO
THE
> > LEFT*/
>
> If you really have only two values, you can try something like
this:
>
> DECLARE VARIABLE ARRAY_IN VARCHAR(5);
> DECLARE VARIABLE ARRAY_OUT VARCHAR(5);
> BEGIN
> ARRAY_IN = 'TTSTS';
> ARRAY_OUT = '';
> WHILE (ARRAY_IN<>'') DO BEGIN
> IF (SUBSTRING(ARRAY_IN FROM 1 FOR 1) = 'T') THEN
> ARRAY_OUT = 'T' || ARRAY_OUT;
> ELSE
> ARRAY_OUT = ARRAY_OUT || 'S';
> ARRAY_IN = SUBSTRING(ARRAY_IN FROM 2 FOR 32767);
> END
> ...
> END
>
> Ivan
> http://www.volny.cz/iprenosil/interbase/
>