Subject | Re: Monthly Report Stored Procedure |
---|---|
Author | Muthu Annamalai |
Post date | 2005-12-10T00:10:18Z |
Lucas,
I have completed the stored procedure as you said.
Here is my new stored procedure
-------Stored Procedure------------
CREATE PROCEDURE REPORT_MONTHLY_SALES
RETURNS (
JAN NUMERIC(15,2),
FEB NUMERIC(15,2),
MAR NUMERIC(15,2),
APR NUMERIC(15,2),
MAY NUMERIC(15,2),
JUN NUMERIC(15,2),
JUL NUMERIC(15,2),
AUG NUMERIC(15,2),
SEP NUMERIC(15,2),
OCT NUMERIC(15,2),
NOV NUMERIC(15,2),
DCR NUMERIC(15,2))
AS
DECLARE VARIABLE MONTHNUM INTEGER;
DECLARE VARIABLE AMT NUMERIC(15,2);
BEGIN
JAN = 0;
FEB = 0;
MAR = 0;
APR = 0;
MAY = 0;
JUN = 0;
JUL = 0;
AUG = 0;
SEP = 0;
OCT = 0;
NOV = 0;
DCR = 0;
FOR SELECT EXTRACT (MONTH FROM RECEIPTDATE),SUM(AMOUNT)
FROM RECEIPT
WHERE EXTRACT(YEAR FROM RECEIPTDATE) = EXTRACT(YEAR FROM
CURRENT_DATE)
GROUP BY 1
INTO :MONTHNUM,:AMT
DO
BEGIN
IF (:MONTHNUM = 1) THEN JAN = AMT;
ELSE IF (:MONTHNUM = 2) THEN FEB = AMT;
ELSE IF (:MONTHNUM = 3) THEN MAR = AMT;
ELSE IF (:MONTHNUM = 4) THEN APR = AMT;
ELSE IF (:MONTHNUM = 5) THEN MAY = AMT;
ELSE IF (:MONTHNUM = 6) THEN JUN = AMT;
ELSE IF (:MONTHNUM = 7) THEN JUL = AMT;
ELSE IF (:MONTHNUM = 8) THEN AUG = AMT;
ELSE IF (:MONTHNUM = 9) THEN SEP = AMT;
ELSE IF (:MONTHNUM =10) THEN OCT = AMT;
ELSE IF (:MONTHNUM =11) THEN NOV = AMT;
ELSE IF (:MONTHNUM =12) THEN DCR = AMT;
END
SUSPEND;
END
-------------------------------------------------
Thanks
Muthu Annamalai
www.pearlpos.com
I have completed the stored procedure as you said.
Here is my new stored procedure
-------Stored Procedure------------
CREATE PROCEDURE REPORT_MONTHLY_SALES
RETURNS (
JAN NUMERIC(15,2),
FEB NUMERIC(15,2),
MAR NUMERIC(15,2),
APR NUMERIC(15,2),
MAY NUMERIC(15,2),
JUN NUMERIC(15,2),
JUL NUMERIC(15,2),
AUG NUMERIC(15,2),
SEP NUMERIC(15,2),
OCT NUMERIC(15,2),
NOV NUMERIC(15,2),
DCR NUMERIC(15,2))
AS
DECLARE VARIABLE MONTHNUM INTEGER;
DECLARE VARIABLE AMT NUMERIC(15,2);
BEGIN
JAN = 0;
FEB = 0;
MAR = 0;
APR = 0;
MAY = 0;
JUN = 0;
JUL = 0;
AUG = 0;
SEP = 0;
OCT = 0;
NOV = 0;
DCR = 0;
FOR SELECT EXTRACT (MONTH FROM RECEIPTDATE),SUM(AMOUNT)
FROM RECEIPT
WHERE EXTRACT(YEAR FROM RECEIPTDATE) = EXTRACT(YEAR FROM
CURRENT_DATE)
GROUP BY 1
INTO :MONTHNUM,:AMT
DO
BEGIN
IF (:MONTHNUM = 1) THEN JAN = AMT;
ELSE IF (:MONTHNUM = 2) THEN FEB = AMT;
ELSE IF (:MONTHNUM = 3) THEN MAR = AMT;
ELSE IF (:MONTHNUM = 4) THEN APR = AMT;
ELSE IF (:MONTHNUM = 5) THEN MAY = AMT;
ELSE IF (:MONTHNUM = 6) THEN JUN = AMT;
ELSE IF (:MONTHNUM = 7) THEN JUL = AMT;
ELSE IF (:MONTHNUM = 8) THEN AUG = AMT;
ELSE IF (:MONTHNUM = 9) THEN SEP = AMT;
ELSE IF (:MONTHNUM =10) THEN OCT = AMT;
ELSE IF (:MONTHNUM =11) THEN NOV = AMT;
ELSE IF (:MONTHNUM =12) THEN DCR = AMT;
END
SUSPEND;
END
-------------------------------------------------
Thanks
Muthu Annamalai
www.pearlpos.com