Solved

Use Record Count

Posted on 2007-04-11
4
622 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

615 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