Subject | How to make this (kind of a sort) inside a stored procedure? |
---|---|
Author | kurei_spin |
Post date | 2006-11-24T16:49:45Z |
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? 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:
DECLARE VARIABLE STR1 VARCHAR(1);
DECLARE VARIABLE STR2 VARCHAR(1);
DECLARE VARIABLE STR3 VARCHAR(1);
DECLARE VARIABLE STR4 VARCHAR(1);
DECLARE VARIABLE STR5 VARCHAR(1);
BEGIN
/*I'LL SET THE VALUES BY MYSELF BY NOW*/
STR1 = 'T';
STR2 = 'T';
STR3 = 'S';
STR4 = 'T';
STR5 = 'S';
/*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*/
/*HERE'S WHAT I'M DOING*/
IF (STR1='S') THEN
BEGIN
SRT1=STR2;
STR2=STR3;
STR3=STR4;
STR4=STR5;
STR5='S';
END
IF (STR2='S') THEN
BEGIN
STR2=STR3;
STR3=STR4;
STR4=STR5;
STR5='S';
END
IF (STR3='S') THEN
BEGIN
STR3=STR4;
STR4=STR5;
STR5='S';
END
IF (STR4='S') THEN
BEGIN
STR4=STR5;
STR5='S';
END
END
It seems to be working perfectly, isn't it? But the problem happens
when I get two 'S' values together. Like: 'T','T','S','S','T'. If I
have these values, the result will be 'T','T','S','T','S'.
So, what you guys say? How can I make this inside a stored
procedure? I'm using Firebird 1.5.
Thanks for helping!
to move some strings inside an array. The first problem is that I
can't use an array inside a stored procedure, right? 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:
DECLARE VARIABLE STR1 VARCHAR(1);
DECLARE VARIABLE STR2 VARCHAR(1);
DECLARE VARIABLE STR3 VARCHAR(1);
DECLARE VARIABLE STR4 VARCHAR(1);
DECLARE VARIABLE STR5 VARCHAR(1);
BEGIN
/*I'LL SET THE VALUES BY MYSELF BY NOW*/
STR1 = 'T';
STR2 = 'T';
STR3 = 'S';
STR4 = 'T';
STR5 = 'S';
/*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*/
/*HERE'S WHAT I'M DOING*/
IF (STR1='S') THEN
BEGIN
SRT1=STR2;
STR2=STR3;
STR3=STR4;
STR4=STR5;
STR5='S';
END
IF (STR2='S') THEN
BEGIN
STR2=STR3;
STR3=STR4;
STR4=STR5;
STR5='S';
END
IF (STR3='S') THEN
BEGIN
STR3=STR4;
STR4=STR5;
STR5='S';
END
IF (STR4='S') THEN
BEGIN
STR4=STR5;
STR5='S';
END
END
It seems to be working perfectly, isn't it? But the problem happens
when I get two 'S' values together. Like: 'T','T','S','S','T'. If I
have these values, the result will be 'T','T','S','T','S'.
So, what you guys say? How can I make this inside a stored
procedure? I'm using Firebird 1.5.
Thanks for helping!