Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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: 6968
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: 6968
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: 6968
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: 6968
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 Update table without cursor Ron Klop DB2 3 Wed Oct 11, 2017 1:06 pm
No new posts Table(Unicode(Graphic) table) loading... muralikrishnan_new DB2 0 Thu Oct 05, 2017 5:10 pm
No new posts Insert a Row_number into table useit DB2 2 Tue Sep 19, 2017 1:07 pm
No new posts how to see when the last read access ... Mike 1304 DB2 1 Tue Sep 12, 2017 7:52 pm
No new posts PC (UTF-8) -> z/OS (EBCDIC) -> ... prino All Other Mainframe Topics 4 Fri Sep 01, 2017 1:47 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us