Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
How to select perticuler row from a table?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
babu_hi

New User


Joined: 11 Apr 2006
Posts: 93

PostPosted: Thu Apr 10, 2008 11:59 am    Post subject: How to select perticuler row from a table?
Reply with quote

I have table like this

TBL_NME TBE_DTE FLAG
T1 000000 E
T2 000000 E
T3 000000 E
T4 000000 E
T5 000000 E
T6 000000 E
T7 000000 E
T8 200712 H
T9 200801 H
T10 200802 H
T11 200803 A
T12 000000 E

and i have declared the cursor like this
EXEC SQL DECLARE CNTL_TABLE_CSR2 CURSOR WITH HOLD FOR
SELECT TBE_NME,
TBE_DTE,
FLAG
FROM ARW_CNTL_TABLE
WHERE CNTL_FLAG = 'H'
FOR UPDATE OF FLAG
END-EXEC.

i want to select only one record which is flag equal is E,if no row is having the flag E then select the older date of flag H from the table.How to select that perticular row?
Back to top
View user's profile Send private message

babu_hi

New User


Joined: 11 Apr 2006
Posts: 93

PostPosted: Thu Apr 10, 2008 12:10 pm    Post subject:
Reply with quote

sorry friends i have written wrong in the above post,i have declared cursor like this,

EXEC SQL DECLARE CNTL_TABLE_CSR2 CURSOR WITH HOLD FOR
SELECT TBE_NME,
TBE_DTE,
FLAG
FROM ARW_CNTL_TABLE
WHERE FLAG = 'H' or FLAG ='E'
FOR UPDATE OF FLAG
END-EXEC.
Back to top
View user's profile Send private message
Srihari Gonugunta

Active User


Joined: 14 Sep 2007
Posts: 295
Location: Singapore

PostPosted: Thu Apr 10, 2008 1:22 pm    Post subject:
Reply with quote

You can do a order by on FLAG ascending & TBE_DTE descending and then you can do a sequential processing till you meet your criteria.
Back to top
View user's profile Send private message
vasanthkumarhb

Active User


Joined: 06 Sep 2007
Posts: 276
Location: Bang,iflex

PostPosted: Thu Apr 10, 2008 1:27 pm    Post subject:
Reply with quote

Hi,
The DECLARE cursor-name statement identifies the cursor, the columns
selected, and the search criteria.
a) The column-names in the SELECT clause (TBE_NME, TBE_DTE, FLAG)
are those of the table.
b) Note that if the WHERE clause is missing we are reading the whole table.
c). We set the Cobol data-name FLAG = 'H' or FLAG ='E' to the correct value since it is used as the search criteria.

that u have declared as below

Code:
EXEC SQL DECLARE CNTL_TABLE_CSR2 CURSOR WITH HOLD FOR
SELECT TBE_NME,
TBE_DTE,
FLAG
FROM ARW_CNTL_TABLE
WHERE FLAG = 'H' or FLAG ='E'
FOR UPDATE OF FLAG
END-EXEC.


For fetching the record means, only one record dont keep FETCH SQL statement in loop such as until SQLCODE = 100 or some other means

do it in a one shot and move it to cobol variables and display it in terminal

For Updation
Code:
EXEC SQL
UPDATE CNTL_TABLE_CSR2
SET FLAG= . . . . .
WHERE CURRENT OF CURSOR-names
END-EXEC.

For fetching

Code:
EXEC SQL
FETCH cursor-name
INTO:TBE_NME:TBE_DTE:FLAG
END-EXEC.
IF SQLCODE TO EQUAL TO ZERO


the very first record that satisfies the condition will be displayed.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1243
Location: Israel

PostPosted: Thu Apr 10, 2008 2:08 pm    Post subject:
Reply with quote

Try:
Code:
WHERE
   (FLAG ='E')
OR
   (FLAG = 'H' AND TBE_DTE = (SELECT MAX(TBE_DTE) FROM ARW_CNTL_TABLE WHERE FLAG = 'H') )
ORDER BY FLAG

Though that may be expensive (in DB2 cost).
With the order by, you will fetch E first if there is, and if not H will come first.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Insert a Row_number into table useit DB2 2 Tue Sep 19, 2017 1:07 pm
No new posts how to see when the last read access ... Mike 1304 DB2 1 Tue Sep 12, 2017 7:52 pm
No new posts PC (UTF-8) -> z/OS (EBCDIC) -> ... prino All Other Mainframe Topics 4 Fri Sep 01, 2017 1:47 am
No new posts Can we limit length in concatenation ... balaji81_k DB2 7 Tue Aug 22, 2017 2:50 am
No new posts Select numeric portion from CHAR data... balaji81_k DB2 6 Sat Aug 19, 2017 1:51 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us