Page 1 of 1

Record Count

PostPosted: Wed Jul 25, 2012 1:58 am
by Vineet
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

Re: Record Count

PostPosted: Wed Jul 25, 2012 2:16 am
by Akatsukami
The record count will always be zero, as DB2 tables contain rows, not records.

Re: Record Count

PostPosted: Wed Jul 25, 2012 3:16 am
by dick scherrer
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.

Re: Record Count

PostPosted: Wed Jul 25, 2012 12:41 pm
by GuyC
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 ;
/*
...

Re: Record Count

PostPosted: Wed Jul 25, 2012 7:45 pm
by dick scherrer
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

Re: Record Count

PostPosted: Wed Jul 25, 2012 8:27 pm
by GuyC
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.

Re: Record Count

PostPosted: Wed Jul 25, 2012 9:10 pm
by dick scherrer
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