Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups 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: 1228
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 unload data from table with lob columns farhad_evan DB2 0 Sat Apr 22, 2017 1:32 pm
No new posts Data replication from multiple Db2 ta... kishpra DB2 9 Mon Mar 27, 2017 9:58 pm
No new posts how to send just 10 rows in a CICS sc... Megha Gupta CICS 5 Thu Feb 23, 2017 6:57 pm
No new posts Join of more than one table dibyendumandal11111 DB2 6 Mon Feb 13, 2017 11:36 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us