Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2011
    Posts
    87

    Unanswered: SQL Query/stored proc help

    DB2 UDB v9.7 / Wondows 2008

    I have been looking to write a sql query or stored proc to export the data from many tables.

    I have a table call REF with two columns which contains employee number and the table number.

    REF

    EMP_NO TABLE_NO
    =================
    AAAA 1
    AAAA 2
    AAAA 4
    BBBB 2
    DDDD 4
    DDDD 1

    If TABLE_NO = 1 then i need to export all the data from EMPLOYEE table for the EMP_NO AAAA and DDDD,
    if TABLE_NO = 2 then i need to export the data from SALARY table for the EMP_NO AAAA and BBBB
    if TABLE_NO = 4 then i need to export the data from BENEFIT table
    .....etc .

    Every table has around million rows.


    How can I do this?
    Please guide me.
    Thanks

  2. #2
    Join Date
    Dec 2007
    Location
    Richmond, VA
    Posts
    1,328
    Provided Answers: 5
    you have to write the SQL for each.

    Such as:
    select * from employee where EMP_NO in ('AAAA','DDDD')

    etc...etc...
    Dave

  3. #3
    Join Date
    Apr 2008
    Location
    Iasi, Romania
    Posts
    561
    Provided Answers: 2
    You may write a script like this:
    EXPORT TO your_file_name
    OF DEL
    SELECT *
    FROM EMPLOYEE
    WHERE EMP_NO IN
    (
    SELECT EMP_NO
    FROM REF
    WHERE TABLE_NO = 1
    )@
    Florin Aparaschivei
    DB2 9.7, 10.5 on Windows
    Iasi, Romania

  4. #4
    Join Date
    Nov 2011
    Posts
    87

    Thank you.

    Thank you aflorin27. It works.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •