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
 

 

SQL to check, if an Employee# exists in a table

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

New User


Joined: 09 Feb 2009
Posts: 57
Location: India

PostPosted: Wed Aug 04, 2010 12:26 am    Post subject: SQL to check, if an Employee# exists in a table
Reply with quote

Hi,

I need an SQL, which could provide me with following output

1. 'Y' when WHERE conditions gets satisfied
2. 'N' when WHERE conditions doesn't get satisfied.

I just need to check, if the corresponding information is present in the table or not. For example, I need to check, if an Employee# exists in a EMPLOYEE table or not. So my Employee# will go into WHERE condition. CASE statement is prohibited, as it creates performance issues.
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Aug 04, 2010 12:46 am    Post subject:
Reply with quote

Quote:
CASE statement is prohibited, as it creates performance issues.


36_11_6.gif icon_butt.gif 36_11_6.gif 12.gif 36_11_6.gif sterb050.gif 36_11_6.gif icon_butt.gif 36_11_6.gif 12.gif 36_11_6.gif sterb050.gif 36_11_6.gif
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Aug 04, 2010 5:00 am    Post subject:
Reply with quote

if it is imbedded sql, you can use cobol code to provide you with the y or n based on sqlcode.

otherwise, I do not see how the following provides a performance problem
Code:

SELECT CASE COUNT(*)
         WHEN 0 THEN 'N'
         ELSE 'Y
       END     AS RESPONSE
INTO :HOST-VARIABLE
FROM your-table
WHERE EMPLOYEE_NO = :HOST-VARIABLE
Back to top
View user's profile Send private message
Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Wed Aug 04, 2010 10:20 am    Post subject:
Reply with quote

Is it important that the SQL should return these values?

Why not
Code:
EVALUATE SQLCODE
    WHEN 0
         MOVE 'Y' TO variable
    WHEN 100
         MOVE 'N' TO variable
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Aug 04, 2010 12:03 pm    Post subject:
Reply with quote

seems the laughs are on me.

the count(*) will force an index scan.

so SELECT 'Y' INTO .. when..
IF SQLCODE <> 0 then move 'N' end-if
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Aug 04, 2010 1:21 pm    Post subject:
Reply with quote

actually the count forces a groupby.
the idxscan is already there.
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 Data replication from multiple Db2 ta... kishpra DB2 5 Mon Mar 27, 2017 9:58 pm
No new posts Check Binary Values for symbols gandikk CA Products 3 Tue Mar 21, 2017 5:11 am
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