Record Count



IBM's flagship relational database management system

Record Count

Postby Vineet » Wed Jul 25, 2012 1:58 am

Hi All,

I am having a Query. Thru JCL I want to Execute Db2 Query To get the Record Count of the Table i.e. Total Number Of Record Present In the Table & the O/P to be written to a File. Out Put File Should have The Record Count Only, apart from Record count Nothing should Present in the file. I appricieate early response.

Thanks
Kind Rgds
Vineet
 
Posts: 86
Joined: Tue Jun 19, 2007 11:38 am
Has thanked: 0 time
Been thanked: 0 time

Re: Record Count

 

Re: Record Count

Postby Akatsukami » Wed Jul 25, 2012 2:16 am

The record count will always be zero, as DB2 tables contain rows, not records.
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1053
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: Record Count

Postby dick scherrer » Wed Jul 25, 2012 3:16 am

Hello,

2 easy options:
Embed your SQL in a bit of code and only write the count to the file.

Write the output from the query to a file and then parse out the count to another file.
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: Record Count

Postby GuyC » Wed Jul 25, 2012 12:41 pm

no need to parse anything :
...
//SYSTSIN  DD  *                                       
DSN SYSTEM(DB2SS)                                       
      RUN  PROGRAM(DSNTIAUL) PLAN(DSNTIAUL) PARMS('SQL')
/*                                                     
//SYSIN  DD  *                 
     SELECT DIGITS(COUNT(*))   
     FROM SYSIBM.SYSDATABASE A 
     WITH UR ;
/*
...
I can explain it to you, but i can not understand it for you.
GuyC
 
Posts: 315
Joined: Tue Aug 11, 2009 3:23 pm
Has thanked: 1 time
Been thanked: 4 times

Re: Record Count

Postby dick scherrer » Wed Jul 25, 2012 7:45 pm

Hi Guy,

On some systems, not everyone can run DSNTIAUL?

Will that place Only the count in the sysout or will there be the "other" things as well (i.e. headers, dash-lines, etc?

d
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: Record Count

Postby GuyC » Wed Jul 25, 2012 8:27 pm

Not every one can submit, JCL or compile a program. I'm giving a possible solution, the viability at a particular site is the OPs problem.

It's an unload, so only the data will be there, in this case a char(10) containing 0000001234, the output file (SYSREC, not SYSOUT) will be FB RECL=10.
You might want to be carefull for null indicators,varchar length fields and so on, if your SQL-statement is a bit more elaborate.
I can explain it to you, but i can not understand it for you.
GuyC
 
Posts: 315
Joined: Tue Aug 11, 2009 3:23 pm
Has thanked: 1 time
Been thanked: 4 times

Re: Record Count

Postby dick scherrer » Wed Jul 25, 2012 9:10 pm

Hi Guy,

Not every one can submit, JCL or compile a program. I'm giving a possible solution, the viability at a particular site is the OPs problem.
My question wasn't a challange :)

Since TS is running the query in batch, i only thought running DSNTIAUL might be a "gotcha".

d

These users thanked the author dick scherrer for the post:
GuyC (Thu Jul 26, 2012 12:26 pm)
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