Page 1 of 1

SQL Query needed.

PostPosted: Sat Nov 01, 2008 1:39 am
by ranga_subham
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.

Re: SQL Query needed.

PostPosted: Sat Nov 01, 2008 1:46 am
by dick scherrer
Hello,

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

I believe we have been thru this before. . .

Re: SQL Query needed.

PostPosted: Sun Nov 02, 2008 12:47 pm
by ranga_subham
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.

Re: SQL Query needed.

PostPosted: Sun Nov 02, 2008 6:14 pm
by dick scherrer
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.