If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Using a While loop instead of a Cursor plz help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-03-05, 10:56
hillcat hillcat is offline
Registered User
 
Join Date: Jan 2004
Location: Montreal, Canada
Posts: 149
Using a While loop instead of a Cursor plz help

what iam trying to do is use a while loop instead of a cursor and iam in the dark can someone please show me the way here is my code:

Declare cursor for
SELECT * FROM VI82BHDT, VI16HPRO
WHERE (NIV182 = NIV116) AND (TYIN16 = 1) AND (PROD82 = PROD16) AND
(NIV182 = :NIV180) AND (NIV282 = :NIV280) AND
(NIV382 = :NIV380) AND (TYIN82 = :TYIN80) AND
(TYTR82 = :TYTR80) AND (NOTR82 = :NOTR80) AND
((:@IEENT = 'I' AND ENTR82 NOT IN(:@ENT01, :@ENT02,
:@ENT03, :@ENT04, :@ENT05) OR ENTR82 = 0) OR
(:@IEENT = 'E' AND ENTR82 IN(:@ENT01, :@ENT02,
:@ENT03, :@ENT04, :@ENT05) AND ENTR82 <> 0)) AND
((:@IEPRO = 'I' AND PROD82 NOT IN(:@PRD01, :@PRD02,
:@PRD03, :@PRD04, :@PRD05, :@PRD06, :@PRD07, :@PRD08)) OR
(:@IEPRO = 'E' AND PROD82 IN(:@PRD01, :@PRD02, :@PRD03,
:@PRD04, :@PRD05, :@PRD06, :@PRD07, :@PRD08))) AND
((:@IEDE1 = 'I' AND DES116 NOT IN(:@DES11, :@DES12,
:@DES13, :@DES14, :@DES15, :@DES16, :@DES17, :@DES18,
:@DES19, :@DES10) OR DES116 = ' ') OR
(:@IEDE1 = 'E' AND DES116 IN(:@DES11, :@DES12,
:@DES13, :@DES14, :@DES15, :@DES16, :@DES17, :@DES18,
:@DES19, :@DES10) AND DES116 <> ' ')) AND
((:@INBD2 = 'X' AND DES216 = ' ') OR
(:@IEDE2 = 'I' AND DES216 NOT IN(:@DES21, :@DES22,
:@DES23, :@DES24, :@DES25) AND DES216 <> ' ') OR
(:@IEDE2 = 'E' AND DES216 IN(:@DES21, :@DES22,
:@DES23, :@DES24, :@DES25) AND DES216 <> ' ')) AND
((:@INBD3 = 'X' AND DES316 = ' ') OR
(:@IEDE3 = 'I' AND DES316 NOT IN(:@DES31, :@DES32,
:@DES33, :@DES34, :@DES35) AND DES316 <> ' ') OR
(:@IEDE3 = 'E' AND DES316 IN(:@DES31, :@DES32,
:@DES33, :@DES34, :@DES35) AND DES316 <> ' ')) AND
((:@INBD4 = 'X' AND DES416 = ' ') OR
(:@IEDE4 = 'I' AND DES416 NOT IN(:@DES41, :@DES42,
:@DES43, :@DES44, :@DES45) AND DES416 <> ' ') OR
(:@IEDE4 = 'E' AND DES416 IN(:@DES41, :@DES42,
:@DES43, :@DES44, :@DES45) AND DES416 <> ' '))
Reply With Quote
  #2 (permalink)  
Old 03-03-05, 11:06
jsp2999 jsp2999 is offline
Registered User
 
Join Date: Jul 2004
Posts: 76
Can u pls. provide detais regarding your requirements and what are all things u have?
Reply With Quote
  #3 (permalink)  
Old 03-03-05, 11:37
Wim Wim is offline
Registered User
 
Join Date: Nov 2004
Posts: 1,279
retrieve the SQL in some kind of datastore
for (int i = 1; i <= datastore.rowCount(); i++) {
// do whatever you want to do with record[i]
}

Is this an answer to your question ?

PS. I would never use "SELECT *" in a program, only use it interactively in an ad hoc way when you explore a database. In a program you should allways specify which columns you want. Just in case an ALTER TABLE happens after jou compiled and deployed your program.

Wim
Reply With Quote
  #4 (permalink)  
Old 03-03-05, 13:43
hillcat hillcat is offline
Registered User
 
Join Date: Jan 2004
Location: Montreal, Canada
Posts: 149
1) How can you code a selection where you can either "include" all records from a specified table "except" up to 5 variables "OR"
"exclude" all records from a specified table "except" up to 5 variables.

2) Is there a way to access the records(one a a time) resulting from the query without using DECLARE CURSOR and FETCH
Reply With Quote
  #5 (permalink)  
Old 03-04-05, 03:32
Wim Wim is offline
Registered User
 
Join Date: Nov 2004
Posts: 1,279
> 1) How can you code a selection where you can either "include" all records from a specified table "except" up to 5 variables "OR"
"exclude" all records from a specified table "except" up to 5 variables.

I don't understand. Please give an example, with the definition of the tables. What do you mean with a "variable" of a table, do you mean "column" ?

> 2) Is there a way to access the records(one a a time) resulting from the query without using DECLARE CURSOR and FETCH

What programming language do you use ?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On