|
|
Question : Count in Procedure
|
|
Total Count Hi: Is there any way in both queries i can count how many rows are return? Also how to i return back to VB.
For i = 0 To UBound(sDistributeID) oDBUtil.ExecuteParamADOCommand cnADOSQL, cmADO, "sp_DistList_DEP_Summary", adCmdStoredProc cmADO.Parameters.Append cmADO.CreateParameter("Input", adVarChar, adParamInput, 3, Trim(sDistributeID(i))) cmADO.Parameters.Append cmADO.CreateParameter("Input", adVarChar, adParamInput, 10, Trim(sClientName(i))) cmADO.Parameters.Append cmADO.CreateParameter("Input", adCurrency, adParamInput, 8, Val(sLower(i))) cmADO.Parameters.Append cmADO.CreateParameter("Input", adCurrency, adParamInput, 8, Val(sUpper(i))) Set rsADO = cmADO.Execute grdSummary.Rows = i + 2 grdSummary.TextMatrix(i + 1, 1) = sBalRangeID(i) grdSummary.TextMatrix(i + 1, 2) = sClientName(i) grdSummary.TextMatrix(i + 1, 3) = sDistributeID(i) grdSummary.TextMatrix(i + 1, 4) = "" & rsADO!DEPCount grdSummary.TextMatrix(i + 1, 5) = "" & rsADO!DEPBal grdSummary.TextMatrix(i + 1, 6) = "" & rsADO!DEPMin grdSummary.TextMatrix(i + 1, 7) = "" & rsADO!DEPMax grdSummary.TextMatrix(i + 1, 8) = "" & rsADO!DEPAvg Set rsADO = Nothing Next i
Thanks.
CREATE PROCEDURE sp_DistList_DEP_Summary @WorkList varchar(3), @Clt_ID varchar(10), @Min money, @Max money AS if not(@max = 0 ) BEGIN SELECT SUM(DUPLICATECOUNT) AS DEPCount, SUM(Cur_BAl) AS DEPBal, MIN(Cur_BAl) AS DEPMin, MAX(Cur_BAl) AS DEPMax, AVG(Cur_BAl) AS DEPAvg FROM tbl_DistList_DEP WHERE (Clt_ID = @Clt_Id) AND (Cur_BAl BETWEEN @Min AND @Max) AND (WorkList = @Worklist) END ELSE BEGIN SELECT SUM(DUPLICATECOUNT) AS DEPCount, SUM(Cur_BAl) AS DEPBal, MIN(Cur_BAl) AS DEPMin, MAX(Cur_BAl) AS DEPMax, AVG(Cur_BAl) AS DEPAvg FROM tbl_DistList_DEP WHERE (Clt_ID = @Clt_Id) AND (Cur_BAl >@Min) AND (WorkList = @Worklist) END GO
|
Answer : Count in Procedure
|
|
-- doh... sorry, wasn't finished... use an output parameter .. not sure what the vb is CREATE PROCEDURE sp_DistList_DEP_Summary @WorkList varchar(3), @Clt_ID varchar(10), @Min money, @Max money, @Count int = 0 OUTPUT AS
if not(@max = 0 ) BEGIN SELECT SUM(DUPLICATECOUNT) AS DEPCount, SUM(Cur_BAl) AS DEPBal, MIN(Cur_BAl) AS DEPMin, MAX(Cur_BAl) AS DEPMax, AVG(Cur_BAl) AS DEPAvg FROM tbl_DistList_DEP WHERE (Clt_ID = @Clt_Id) AND (Cur_BAl BETWEEN @Min AND @Max) AND (WorkList = @Worklist)
SET @Count = @@ROWCOUNT END ELSE BEGIN SELECT SUM(DUPLICATECOUNT) AS DEPCount, SUM(Cur_BAl) AS DEPBal, MIN(Cur_BAl) AS DEPMin, MAX(Cur_BAl) AS DEPMax, AVG(Cur_BAl) AS DEPAvg FROM tbl_DistList_DEP WHERE (Clt_ID = @Clt_Id) AND (Cur_BAl >@Min) AND (WorkList = @Worklist)
SET @Count = @@ROWCOUNT END GO
|
|
|
|
|