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 SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
No new posts What is the command to check MODE of ... rohanthengal CLIST & REXX 7 Fri Nov 18, 2016 1:48 pm
No new posts Check System time(Minute) Using TIME1... balaji81_k DFSORT/ICETOOL 5 Fri Nov 11, 2016 10:53 am
No new posts Need Rexx Program to Load in to DB2 T... Hareesh Verma CLIST & REXX 22 Tue Sep 20, 2016 2:59 pm
No new posts Command UNIQUE CONSTRAINT on any tabl... rohanthengal DB2 2 Thu Aug 18, 2016 3:48 pm


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