Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get first rows

Status
Not open for further replies.

craig322

MIS
Apr 19, 2001
108
US
Is there a way other than SAMPLE to get rows from a table?

I am writing some error checking to verify that a table is populated using the ACTIVITYCOUNT feature. The tables I am running it against are rather large tables and if I use a statment like the following, it is taking a long time.

SELECT *
FROM large_table
SAMPLE 2;

.IF ACTIVITYCOUNT > 1 THEN .GOTO CONTPROC

Doing a count of the table always returns 1 row, so this doesn't work.

Does anyone have any ideas?

Thanks

Craig
 
Hi,
Activitycount works best with HAVING clause.

sel 1 from
mytable
having count(*) > 0;

.IF ACTIVITYCOUNT>0 THEN .GOTO CONTPROC

/* OOPS I guess I need to load this */
/* .OS out to SH and run my fastload script */

.os /home/user/loadmytable

.LABEL CONTPROC
 
Or even:

SELECT 'ERROR - NO ROWS IN TAB1'
WHERE 0 = (SELECT COUNT(*) FROM TAB1)
;
.IF ACTIVITYCOUNT = 1 THEN .QUIT 16

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top