A small help in changing a cursor.



IBM's flagship relational database management system

A small help in changing a cursor.

Postby gabbar » Thu Dec 06, 2012 1:19 pm

there is a table
id1      company id                vendor id           ACCOUNTS
1          abc                            xyz                            4
2          abc                            xyz                            4
3          abc                            xyz                            4

what happened is that the vendor provides id1 to us, where as we give a company id to every id1. we decided to club a few id1 together under the same company id. previously when id1 was 1 company id was abc.. when it was 2 company id was def and when it was 3 the company id was ghi but we decided to club 1 2 and 3 together so all three will have the same company id. NOTE: we cannot change the table data

previously i used a cursor
SELECT company id, product name,vendor id, accounts                     
     FROM TABLENAME                           
 WHERE CONDITION
 ORDER BY THE ATTRIBUTES I WANT.

SO WHEN I SEE THE DISPLAY OF THE CURSOR NOW EVERYTHING WITH ID 1 ,2,3 GIVES THE SAME DATA NOW SO IT IS DISPLAYED THRICE IN THE FRONT END

but as all three have been clubbed it has to be displayed only once
so i used a cursor
SELECT max(company id),
            product name,vendor id
          , max(accounts)
     FROM tables
 WHERE conditons
 group by product name
     , company id
     , vendor id
 ORDER BY whatever

as all the values for various id1 are the same when they are clubbed when i use max i will get only 1 value and that is what i want but i want to know if there is a more efficient way to solve this problem.
gabbar
 
Posts: 12
Joined: Fri Dec 23, 2011 11:49 am
Has thanked: 0 time
Been thanked: 0 time

Re: A small help in changing a cursor.

Postby gabbar » Thu Dec 06, 2012 2:48 pm

DONE GOT IT THANK YOU
gabbar
 
Posts: 12
Joined: Fri Dec 23, 2011 11:49 am
Has thanked: 0 time
Been thanked: 0 time


Return to DB2

 


  • Related topics
    Replies
    Views
    Last post