I have an SQR Begin-Select
statement which SELECTS
a bunch of data and returns it for processing the SQR report. There is a possibility that the Begin-Select
will return nothing, so that means there is nothing to report.
How would I check if the Begin-Select
returns no rows in it's statement?
I thought about including a COUNT(*)
in the Begin-Select
, but I don't want to GROUP BY
anything. Here's what my Begin-Select
looks like.
Begin-Select On-Error=Global-Got-Fatal-SQL-Error
B.InvrExtAcctNbr &InvrLoanNbr
A.AcctNbr &AcctNbr
C.RtxnNbr &AcctGrpNbr
!- Process each record
#Debug Show 'Processing AcctNbr: ' &AcctNbr
!Do Process-Record
#Debug Show 'Processed AcctNbr: ' &AcctNbr
FROM FooBar A,
JohnDoe B,
SQRNoob C
WHERE A.QueNbr = $QueNbr /* 123 */
AND A.QueSubNbr = $QueSubNbr /* 456 */
AND A.ApplNbr = $ApplNbr /* 789 */
AND A.AcctNbr = C.AcctNbr
AND A.RtxnNbr = B.AcctGrpNbr
ORDER BY A.AcctNbr
End-Select
I want to check if anything got returned from the Begin-Select
. I've tried this:
Begin-Select On-Error=Global-Got-Fatal-SQL-Error
COUNT(A.AcctNbr) &TotalRows
B.InvrExtAcctNbr &InvrLoanNbr
A.AcctNbr &AcctNbr
C.RtxnNbr &AcctGrpNbr
...
But I don't want to use a GROUP BY
clause at the end of my statement. I also don't want to break it up into two seperate SELECT
statements. One for the actual selection of data and the other for COUNT(A.AcctNbr)
.
Is there any other way to get the amount of rows returned from this SELECT statement.
My whole issue is I don't have to process the form if no rows are returned. So in reality I only need to check if the Begin-Select
returns one or more rows. If it returns no rows, then I would just stop processing the SQR.
Well, brute force method:
Let #Count = 0
Begin-Select
Variables
add 1 to #Count
From etc
End-Select
If #Count = 0
Easiest way I can think of - I tried #SQL-COUNT but that only works for Insert, Delete, and Update statements, not select.