Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » ElevateDB Technical Support » Support Forums » ElevateDB SQL » View Thread |
Messages 1 to 10 of 12 total |
Procedure and while |
Sat, May 10 2008 10:44 AM | Permanent Link |
Dieter Nagy | Hello,
I use the following code for insert: PREPARE stmt FROM 'INSERT INTO Zwei(Erste,Zweite) Values (?,?)'; while ZAEHLER < 44 do EXECUTE stmt USING ZAHL,ZAHL1; SET ZAHL = ZAHL; SET Zahl1 = zahl1+1; SET ZAEHLER = ZAEHLER+1; END WHILE; PREPARE stmt FROM 'INSERT INTO Zwei(Erste,zweite) Values (?,?)'; SET zaehler = 1; SET ZAHL1 = 3; SET zahl =2; while ZAEHLER < 44 do EXECUTE stmt USING ZAHL,ZAHL1; SET ZAHL = 2; SET ZAHL1 = ZAHL1+1; SET ZAEHLER = ZAEHLER+1; END WHILE; PREPARE stmt FROM 'INSERT INTO Zwei(Erste,zweite) Values (?,?)'; SET zaehler = 1; SET ZAHL1 = 4; SET zahl =3; while ZAEHLER < 43 do EXECUTE stmt USING ZAHL,ZAHL1; SET ZAHL = 3; SET ZAHL1 = ZAHL1+1; SET ZAEHLER = ZAEHLER+1; and so on........till the zahl = 45. Is there a better way to do this? Please help... TIA Dieter |
Sat, May 10 2008 11:03 AM | Permanent Link |
Uli Becker | Dieter
> PREPARE stmt FROM 'INSERT INTO Zwei(Erste,Zweite) Values (?,?)'; > while ZAEHLER < 44 do > EXECUTE stmt USING ZAHL,ZAHL1; > SET ZAHL = ZAHL; > SET Zahl1 = zahl1+1; > SET ZAEHLER = ZAEHLER+1; > END WHILE; >... That looks quite confusing. It would help to describe which result you want to see respectively which rule is behind your statements. Uli |
Sat, May 10 2008 11:12 AM | Permanent Link |
Dieter Nagy | Uli,
after finish it should like this: 1 2 1 3 1 4 1 5 1 6 ... 2 3 2 4 2 5 .... 3 4 3 5 3 6 ..... 44 45 I hope you now what I mean... TIA Dieter Uli Becker <test@test.com> wrote: Dieter > PREPARE stmt FROM 'INSERT INTO Zwei(Erste,Zweite) Values (?,?)'; > while ZAEHLER < 44 do > EXECUTE stmt USING ZAHL,ZAHL1; > SET ZAHL = ZAHL; > SET Zahl1 = zahl1+1; > SET ZAEHLER = ZAEHLER+1; > END WHILE; >... That looks quite confusing. It would help to describe which result you want to see respectively which rule is behind your statements. Uli |
Sat, May 10 2008 11:35 AM | Permanent Link |
Uli Becker | Dieter,
> after finish it should like this: > > 1 2 > 1 3 > 1 4 > 1 5 > 1 6 > .. > 2 3 OK, then you could try this (a loop for the second entry within the first loop): SCRIPT BEGIN DECLARE stmt STATEMENT; DECLARE Counter1 integer; DECLARE Counter2 integer; SET Counter1 = 1; SET Counter2 = Counter1 + 1; PREPARE stmt FROM 'INSERT INTO Zwei(Erste,Zweite) Values (?,?)'; WHILE Counter1 < 45 do WHILE Counter2 < 45 do EXECUTE stmt USING Counter1,Counter2; SET Counter2 = Counter2 + 1; END WHILE; SET Counter1 = Counter1 + 1; SET Counter2 = Counter1 + 1; END WHILE; END |
Sat, May 10 2008 11:55 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Dieter
I don't know without trying it if Tim's stuff will support nested while loops but I suspect it will. So all you should need is two loops - something along the lines of procedure TForm1.Button1Click(Sender: TObject); var a:integer; b:integer; begin a:=1; while a <= 45 do begin b:=a+1; while b <= 45 do begin memo1.lines.Add(inttostr(a)+' '+inttostr(b)); inc(b); end; inc(a); end; end; Which I think does what you're after Until Tim comes up with his debugger its a good idea to try these sorts of things out in Delphi and then translate - at least its a language you're more familiar with I hope So the above would translate to something like PREPARE stmt FROM 'INSERT INTO Zwei(Erste,Zweite) Values (?,?)'; SET ZAHL = 1; WHILE ZAHL <=45 DO BEGIN SET ZAHL1 = ZAHL + 1; WHILE ZAHL1 <= 45 DO BEGIN EXECUTE stmt USING ZAHL,ZAHL1; SET ZAHL1 = ZAHL1 + 1; END WHILE; SET ZAHL = ZAHL + 1; END WHILE Roy Lambert [Team Elevate] |
Sat, May 10 2008 11:57 AM | Permanent Link |
Dieter Nagy | Uli,
many thanks for your help. Dieter Uli Becker <test@test.com> wrote: Dieter, > after finish it should like this: > > 1 2 > 1 3 > 1 4 > 1 5 > 1 6 > .. > 2 3 OK, then you could try this (a loop for the second entry within the first loop): SCRIPT BEGIN DECLARE stmt STATEMENT; DECLARE Counter1 integer; DECLARE Counter2 integer; SET Counter1 = 1; SET Counter2 = Counter1 + 1; PREPARE stmt FROM 'INSERT INTO Zwei(Erste,Zweite) Values (?,?)'; WHILE Counter1 < 45 do WHILE Counter2 < 45 do EXECUTE stmt USING Counter1,Counter2; SET Counter2 = Counter2 + 1; END WHILE; SET Counter1 = Counter1 + 1; SET Counter2 = Counter1 + 1; END WHILE; END |
Sat, May 10 2008 12:00 PM | Permanent Link |
Uli Becker | Roy,
that's exactly what I posted, isn't it? Regards Uli |
Sat, May 10 2008 1:32 PM | Permanent Link |
Fernando Dias Team Elevate | Uli,
> that's exactly what I posted, isn't it? No. Your code doesn't generate the pairs (1,45), (2,45)...(44,45). -- Fernando Dias [Team Elevate] |
Sat, May 10 2008 1:39 PM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Uli
Very near, and according to the timestamp about 25 mins before me Roy Lambert |
Sat, May 10 2008 1:55 PM | Permanent Link |
Uli Becker | Fernando,
> > No. > Your code doesn't generate the pairs (1,45), (2,45)...(44,45). I don't understand what you mean. You mean because of < instead of <=? It was my intention to show the principle of the nested loops nothing else. Uli |
Page 1 of 2 | Next Page » | |
Jump to Page: 1 2 |
This web page was last updated on Tuesday, April 30, 2024 at 03:55 PM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |