IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

DB2 Record existence checking


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
abdul

EXPERT


Joined: 28 Jul 2003
Posts: 23
Location: Bangalore,India

PostPosted: Tue Jun 15, 2004 8:51 am
Reply with quote

Hi,
Can anyone help me with a method to check whether a single record exists in a DB2 Table without using COUNT(*).
Thanks
Abdul
Back to top
View user's profile Send private message
GG

New User


Joined: 10 Jul 2004
Posts: 1

PostPosted: Sat Jul 10, 2004 11:17 pm
Reply with quote

EXEC SQL
SELECT 1
INTO :WS-COUNT
FROM <dbname>.<tbname>
WHERE ?
END-EXEC

IF SQLCODE EQUAL ROW-FOUND
DISPLAY 'SQLCODE = ROW FOUND'
ELSE
IF SQLCODE EQUAL ROW-NOT-FOUND
DISPLAY 'SQLCODE = ROW NOT FOUND'
ELSE
IF SQLCODE EQUAL MULTI-ROWS
DISPLAY 'SQLCODE = MULTIPLE ROWS FOUND'
ELSE
DISPLAY 'PGM T88TST - PG 3000 -'
' - BAD STUFF IS HAPPENING WITH THE SQLCODE '
DISPLAY 'SQLCODE ' SQLCODE
DISPLAY 'SQLERRMC ' SQLERRMC
MOVE Y TO TIME-TO-QUIT-FLAG
GO TO 3000-EXIT
.


The singleton does kick out an SQL Error code -811 when duplicates occur - the way it performs (SELECT 1), it only expects one row to be returned. Sometimes its nice to know if there are duplicates.


---------------------------------------------------------------------

EXEC SQL
SELECT 1
INTO :WS-COUNT
FROM SYSIBM.SYSDUMMY1 A
WHERE EXISTS
(SELECT 1
FROM <dbname>.<tbname> B
WHERE ?
AND A.IBMREQD = A.IBMREQD
)
END-EXEC

IF SQLCODE EQUAL ROW-FOUND
DISPLAY 'SQLCODE = ROW FOUND'
ELSE
IF SQLCODE EQUAL ROW-NOT-FOUND
DISPLAY 'SQLCODE = ROW NOT FOUND'
ELSE
DISPLAY 'PGM T88TST - PG 3000 -'
' - BAD STUFF IS HAPPENING WITH THE SQLCODE '
DISPLAY 'SQLCODE ' SQLCODE
DISPLAY 'SQLERRMC ' SQLERRMC
MOVE Y TO TIME-TO-QUIT-FLAG
GO TO 3000-EXIT
.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts how to complete the end of a record w... DFSORT/ICETOOL 2
No new posts Sort based on the record type DFSORT/ICETOOL 1
No new posts Get RECORD LENGTH, allocated space of... CLIST & REXX 7
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
Search our Forums:

Back to Top