× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Jerry,
I think if you have an index on "months", then
your FETCH FIRST should work - and the testing
should be a snap.

-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Jerry C. Adams
Sent: Monday, August 13, 2012 12:16 PM
To: 'Midrange Systems Technical Discussion'
Subject: COUNT(*) or FETCH Faster?

No referential integrity constraints here. Usually, when I want to check for records in a secondary file before I allow a delete of, say, a customer master record, I just used SQL SELECT with COUNT(*) and return that to the maintenance program.



Works okay, but now I need to check an invoice history table which has about
2,000,000 records, but I only want to check for the last twelve [12] months.




I was wondering if a SELECT into a cursor and then a FETCH FIRST 1 ROWS ONLY might be faster.



I'm pretty sure the COUNT(*) option has to process all of the records for the period I pass to it. I figured the SELECT into a cursor did, too, but don't know for sure.



Thanks.



Jerry C. Adams

IBM i Programmer/Analyst

Try to look unimportant; the enemy may be low on ammo and not want to waste a bullet on you.

--

A&K Wholesale

Murfreesboro, TN

615-867-5070



--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/midrange-l.




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.