Try this:
dcl-s TheCount int(10);
Exec Sql
Select count(*)
Into :TheCount
From file1;
Thanks,
Marvin
No trees were killed in the sending of this message, but a large number of electrons were terribly inconvenienced, traumatized, triggered, and crying for their safe spaces.
-----Original Message-----
From: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Dan
Sent: Friday, April 06, 2018 1:17 PM
To: RPG400-L@xxxxxxxxxxxx
Subject: Return count of records from SQL select
I must be ready for the weekend, as I can't seem to remember how to do this in RPG.
I need to know ONLY the number of rows that would be returned from an SQL select statement. I don't need to know anything about the rows themselves. The decision I need to make is based on whether the number of rows from the select statement is zero or greater than zero.
I tried:
Exec SQL set :TheCount = select count(*) as aCount from File1; which gave me:
SQL0312 30 7 Position 22 Variable THECOUNT not defined or not
usable.
SQL0199 30 7 Position 40 Keyword COUNT not expected. Valid
tokens:
I tried:
Exec SQL select * from File1;
Exec SQL Get Diagnostics :TheCount = Row_Count; which gave me:
SQL0029 30 7 Position 17 INTO clause missing from embedded
statement.
SQL0312 30 8 Position 34 Variable THECOUNT not defined or not
usable.
- Dan
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit:
https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
https://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxx for any subscription related questions.
Help support midrange.com by shopping at amazon.com with our affiliate link:
http://amzn.to/2dEadiD
Notice: This e-mail transmission may contain information that is proprietary, privileged and/or confidential and is intended exclusively for the person(s) to whom it is addressed. This message may also contain Protected Health Information (PHI) and must be treated confidentially and handled in accordance with HIPAA and other federal and state privacy laws. Any use, copying, retention or disclosure by any person other than the intended recipient or the intended recipient's designees is strictly prohibited. If you are not the intended recipient or their designee, please notify the sender immediately and delete this e-mail (and any accompanying attachments).
As an Amazon Associate we earn from qualifying purchases.