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
 

 

DB2 Record existence checking

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: DB2 Record existence checking
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    Post subject: Existence check
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    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 How to update a portion of text in a ... Bill Woodger DFSORT/ICETOOL 25 Wed Nov 09, 2016 9:41 pm
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am
No new posts Syncsort - NULL in Integer field chec... nartcr SYNCSORT 4 Thu Oct 06, 2016 6:47 am
No new posts sort with previous record anatol DFSORT/ICETOOL 9 Thu Oct 06, 2016 2:36 am
No new posts Get Record count in summary record fo... Atul Banke DFSORT/ICETOOL 21 Fri Sep 23, 2016 4:17 pm


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