Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Cursor required or not to get only the counts

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
k.junaid83

New User


Joined: 19 Apr 2006
Posts: 22
Location: bangalore

PostPosted: Thu Aug 30, 2007 10:12 am    Post subject: Cursor required or not to get only the counts
Reply with quote

Hi All,

I have a DB2 table name Employee.The columns are EMP_TYPE,EMP_NO,EMP_NAME,EMP_ADDRESS.
I am writting a cobol program to Get the counts of the rows based on the EMP_TYPE.For eg the values for EMP_TYPE is 10,20,30,40 etc.
I need to get the count for the number of the Employees with EMP_TYPE = 10 ,EMP_TYPE = 20....... .
My question is whether we need a Cursor to get the Counts for each EMP_TYPE or just a single query will do ?


Thanks in Advance
Back to top
View user's profile Send private message

Prajesh_v_p

Active User


Joined: 24 May 2006
Posts: 133
Location: India

PostPosted: Thu Aug 30, 2007 10:23 am    Post subject: Reply to: Cursor required or not to get only the counts
Reply with quote

You might need to use a cursor if you want to retrieve count for more than one emp type and you are not aware of the diffrent emp types available in the emp table.

Thanks,
Prajesh
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6967
Location: porcelain throne

PostPosted: Thu Aug 30, 2007 12:51 pm    Post subject:
Reply with quote

If you are on db2 V7 or later:
Code:

SELECT DISTINCT EMP_TYPE
     , COUNT(DISTINCT EMP_TYPE)
FROM your-table
ORDER BY 1
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6967
Location: porcelain throne

PostPosted: Thu Aug 30, 2007 1:13 pm    Post subject:
Reply with quote

Sorry, last post sucks. Try

Code:

SELECT EMP_TYPE
    ,  COUNT(EMP_TYPE)
FROM your-table
GROUP BY EMP_TYPE
ORDER BY EMP_TYPE;
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 Testing rerad cursor for status with ... John F Dutcher DB2 7 Fri May 19, 2017 9:35 pm
No new posts IMS T-Pipe queue counts in a COBOL Pr... Siva NKK Kothamasu IMS DB/DC 0 Tue May 09, 2017 6:31 pm
No new posts Getting -504 Cursor Name GTT-ARTS-CUR... Robin Sulsona DB2 2 Fri Mar 17, 2017 1:43 am
No new posts Release of Adabas Cursor mohitsethi All Other Mainframe Topics 1 Mon Feb 06, 2017 8:36 pm
No new posts Updating Cursor row withour using FOR... chandan.inst DB2 15 Tue Nov 08, 2016 11:17 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us