Solved

Use Record Count

Posted on 2007-04-11
4
618 Views
Last Modified: 2008-01-09
Hi: Can any one please tell me how to i use the recordcount in that query
select clt_ref_no as CFG_ACCOUNT,
(case  
         when r.status_code in ('400','404','407') then 'OVBK'
        when r.status_code in ('210','420','430','470','630','475') then 'OVUN'
        when r.status_code in ('435','438') then 'OVRC'
        when r.status_code in ('450') then 'OVDC'
        when r.status_code in ('487','485') then 'OVFA'
        when r.status_code = '491' then 'OCAC'
        when r.status_code = '510' then 'OSIF'
        when r.status_code='520' then 'OPIF'
        else 'CHECK STATUS'
       END) as REASON,
(SELECT LONGSTR FROM DBTRUDF U WHERE R.DEBTOR_ID=U.DEBTOR_ID AND LABEL='BANKRUPTCYCHAPTER') AS BANKRUPTCYCHAPTER,
(SELECT LONGSTR FROM DBTRUDF U WHERE R.DEBTOR_ID=U.DEBTOR_ID AND LABEL='CASENUMBER') AS CASENUM,
CONVERT(CHAR(10),(SELECT DATE1 FROM DBTRUDF U WHERE R.DEBTOR_ID=U.DEBTOR_ID AND LABEL='FILEDATE'),101) AS BKTFILEDATE,
CONVERT(CHAR(10),(SELECT DATE1 FROM DBTRUDF U WHERE R.DEBTOR_ID=U.DEBTOR_ID AND LABEL='DECEASEDDATE'),101) AS DATEOFDEATH,
    STATUS_DESCR AS COMMENTS,
    substring(DEBT_DESCR,(LOCATE(DEBT_DESCR,':',1)+1), 30) AS ORIGINALACCOUNT
FROM DEBT_VIEW S JOIN DBTR R ON S.DEBT_ID=R.DEBTOR_ID
WHERE CLT_ID LIKE 'IDTC%' AND R.STATUS_CODE>='400'  AND R.STATUS_DATE> '04-11-07'

Thanks.
0
Comment
Question by:mustish1
  • 2
4 Comments
 
LVL 19

Expert Comment

by:grant300
ID: 18890967
I am not sure what you are asking.  Is this in a stored proc and you want to know how many rows were returned?

Immediately after DML statement, the global variable @@ROWCOUNT will tell you how many rows were returned/affected by the operation.

Regards,
Bill
0
 

Author Comment

by:mustish1
ID: 18891122
No its not in a stored procedure. If you please tell me how to i use the count(*) in the query which gives me only a total number of row count in the query?
Thanks.
0
 
LVL 19

Accepted Solution

by:
grant300 earned 500 total points
ID: 18891670
COUNT(*), like the other aggregate functions (MIN, MAX, AVG, etc) only works properly in the context of a query with a GROUP BY clause.

Since you are returning individual rows, the COUNT(*) aggregate does not give you what you want.  Even if you added the GROUP BY in such a way it did not affect your query otherwise, you would simply get "1" for the COUNT(*) on each row.

Depending on what you are using for client software, you could put the COUNT(*) in a COMPUTE clause.  Unfortunately, COMPUTE is a Sybase-only extension to SQL that never gained wide popularity or support so very few tools know what to do with it.

Your best bet is to put the whole thing in a SQL block and return the value of @@ROWCOUNT as a second result set.  For example....

BEGIN
 SELECT clt_ref_no as CFG_ACCOUNT,
     o
     o
  WHERE CLT_ID LIKE 'IDTC%' AND R.STATUS_CODE>='400'  AND R.STATUS_DATE> '04-11-07'

  SELECT @@ROWCOUNT as RowCount
END

Regards,
Bill

0
 
LVL 29

Expert Comment

by:leonstryker
ID: 18892433
If you just want to test the number of rows this query will return you could use this:

SELECT COUNT(*)
FROM DEBT_VIEW S JOIN DBTR R ON S.DEBT_ID=R.DEBTOR_ID
WHERE CLT_ID LIKE 'IDTC%' AND R.STATUS_CODE>='400'  AND R.STATUS_DATE> '04-11-07'

But this would have to be run independent of your original query. You could run them one afer the other by seting the count to a variable, but in effect you are executing the query twice.

Leon
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sybase SQL Syntax 2 282
dbisql 5 614
Quickbooks Database Server Manager services crashes when file is opened 15 3,614
SAP HANA use case satisfy OLAP applications only. How true? 7 253
One of the biggest threats in the cyber realm pertains to advanced persistent threats (APTs). This paper is a compare and contrast of Russian and Chinese APT's.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question