SQL Query needed.



IBM's flagship relational database management system

SQL Query needed.

Postby ranga_subham » Sat Nov 01, 2008 1:39 am

Hi,

I need a SQL query for the following condition.

Select employee-numbers for date 11th October 2008 who has request number "JZSK008" and for the date 12th October 2008 who has request number "KZSK009".


Please help.

Thanks.
ranga_subham
 
Posts: 279
Joined: Fri Jul 18, 2008 7:46 pm
Has thanked: 0 time
Been thanked: 1 time

Re: SQL Query needed.

 

Re: SQL Query needed.

Postby dick scherrer » Sat Nov 01, 2008 1:46 am

Hello,

You need to post what you have tried and what problem(s) were encountered. . .

I believe we have been thru this before. . .
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: SQL Query needed.

Postby ranga_subham » Sun Nov 02, 2008 12:47 pm

This is what I tried.........

SELECT EMPLOYEE_NUM                                             
  FROM CONADB.EMPLOYEE                                         
  WHERE REQST_NUM = 'JZSK008'                                         
    AND TIM_STMP BETWEEN '2008-10-11-00.00.00.000000'
                    AND '2008-10-11-23.59.59.000000'       
    AND EXISTS                                                       
        (SELECT EMPLOYEE_NUM
           FROM CONADB.EMPLOYEE                         
          WHERE REQST_NUM = 'KZSK009'                                 
            AND TIM_STMP BETWEEN '2008-10-12-00.00.00.000000'
                            AND '2008-10-12-23.59.59.000000')
WITH UR;               


Thanks.
ranga_subham
 
Posts: 279
Joined: Fri Jul 18, 2008 7:46 pm
Has thanked: 0 time
Been thanked: 1 time

Re: SQL Query needed.

Postby dick scherrer » Sun Nov 02, 2008 6:14 pm

Hello,

So, you want multiple "answers rows" returned from the query?

You will probably be better served using a cursor (unless your environment supports multi-row fetch (check with your dba to see if this is available and how to use it if it is)).

The declare cursor could use something like this in the the "where":
WHERE (REQST_NUM = 'JZSK008'                                         
      AND TIM_STMP BETWEEN '2008-10-11-00.00.00.000000'
                       AND '2008-10-11-23.59.59.000000' )
  OR (REQST_NUM = 'KZSK009'                                 
      AND TIM_STMP BETWEEN '2008-10-12-00.00.00.000000'
                       AND '2008-10-12-23.59.59.000000')


In the processing code, you wouold open the cursor and fetch the rows (one at a time) that match your criteria and do whatever is needed for each row read.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times


Return to DB2

 


  • Related topics
    Replies
    Views
    Last post