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

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


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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: 6965
Location: porcelain throne

PostPosted: Wed Aug 04, 2010 12:46 am
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: 6965
Location: porcelain throne

PostPosted: Wed Aug 04, 2010 5:00 am
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
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: 6965
Location: porcelain throne

PostPosted: Wed Aug 04, 2010 12:03 pm
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: 6965
Location: porcelain throne

PostPosted: Wed Aug 04, 2010 1:21 pm
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 All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts count contained values of several col... DB2 4
No new posts To join 2 tables and to join 3rd tabl... DB2 8
No new posts Create a specific record/file based o... SYNCSORT 8
No new posts Extract ISPF table column headings CLIST & REXX 2
No new posts Using Multiple IFTHEN and WHEN condit... SYNCSORT 12
Search our Forums:


Back to Top